Hi...I'm trying to figure out how would I be able to create an ini file within my code...when the user runs a program I want to be able to create an ini file to store information without the user knowing about it.
Public Declare Function WritePrivateProfileString _
Lib "kernel32" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationname As String, ByVal lpKeyName As Any, _
ByVal lsString As Any, ByVal lplFilename As String) As Long
Public Declare Function GetPrivateProfileString Lib _
"kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationname As String, ByVal lpKeyName As _
String, ByVal lpDefault As String, ByVal lpReturnedString _
As String, ByVal nSize As Long, ByVal lpFileName As String) _
As Long
Then to write/create:
WritePrivateProfileString "Title", "Key", "Whatever you want to write", "full path and name of ini"
And to read the data:
'Set temp to 100 chars long (or anything long enough to
'Load default mailto address from ini file
temp = String$(100, vbNullChar)
temp = Left$(temp, GetPrivateProfileString("Title", "Key", "full path and name of ini", temp, Len(temp), "full path and name of ini")
'Temp will then hold the returned ini data
Note that the "Title" and "Key" can be anything, such as the app title and sub category. You can use the same title but different keys for multiple entries in the same ini, and by calling a specified key it picks the relevant one for you.
or use the below FSO
(Set a reference to the "Micosoft Scriting Runtime"
Public Sub CreateIni(ByVal sPath As String, ByVal sIniName As String)
Dim fso As New Scripting.FileSystemObject
Dim f As Scripting.TextStream
Dim sPathAndName as string
sPathAndName =fso.BuildPath(sPath, sIniName)
fso.CreateTextFile sPathAndName ,overwrite:=True
Set f = fspenTextFile(sPathAndName, IOMode:=ForAppending, Create:=False)
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.