' Read INI file
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
' Write INI file
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As Any, ByVal lpString As Any, ByVal lpFileName As String) As Long
Public Function sGet_INI_String(rsSection As String, rsEntry As String) As String
' ------------------------
' Retrieve INI file string
' ------------------------
Dim lReturn As Long
Dim sINIString As String
Dim sEntry As String
Dim rsFileName As String
rsFileName = gsINIPATH
' Initialise buffer - safer and quicker
' than fixed length string
sINIString = Space$(255)
' rsEntry must be assigned to local variable to work
sEntry = rsEntry
If lReturn > 0 Then
sGet_INI_String = Left$(sINIString, lReturn)
Else
sGet_INI_String = ""
End If
End Function
Sub Write_INI_String(rsSection As String, rsEntry As String, rsValue As String)
' ---------------------
' Write INI file string
' ---------------------
Dim lReturn As Long
Dim rsFileName As String
rsFileName = gsINIPATH
If rsEntry <> "" Then
lReturn = WritePrivateProfileString(rsSection, rsEntry, rsValue, rsFileName)
Else
' To remove Section
lReturn = WritePrivateProfileString(rsSection, vbNullString, rsValue, rsFileName)
End If
If lReturn = 0 Then
' Error
End If
End Sub
NOTE that these two routines use a global variable -gsINIPATH- which is used to store the path of the ini file.
And then to read from the ini file, do this:
Dim sDatabasePath As String
sDatabasePath = sGet_INI_String("Database", "Path"
NOTE that these two routines use a global variable - gsINIPATH - which is used to store the path of the ini file.
I've done everything but because I'm not sure what you mean by this then it doesn't write and I get an error message. Please could you explain what to do with gsINIPATH so that I can write and read ini.
Hi... Sorry, I've solved the problem I mentioned above but could you give me advice about...
I have added the directory path to the ini file which holds the information but what happens when other people install the application and your directory location is still in the module? Does the install procedure rectify this????
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.