I would use API calls to getinistring and writeinistring:
In your project, have a module with the following code:
' Read INI file
Declare Function GetPrivateProfileInt Lib "kernel32" Alias "GetPrivateProfileIntA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal nDefault As Long, ByVal lpFileName As String) As Long
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 ' global variable holding full path and name of ini file
' Initialise buffer - safer and quicker
' than fixed length string
sINIString = Space$(255)
' rsEntry must be assigned to local variable to work
sEntry = rsEntry
lReturn = GetPrivateProfileString(rsSection, sEntry, "", sINIString, Len(sINIString), rsFileName)
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 ' global variable holding full path and name of ini file
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
In your app, call the functions by:
1. to read the ini file:
Dim sString AS String
sString = sGet_INI_String("Database", "Path"
2. to write to the ini file:
Write_INI_String "Database", "Path", "C:\data.mdb"
Your ini file would be a normal text file (I normally call mine data.ini - or sometimes name_of_project.ini) which you can edit in Notepad and would look like this:
[Database]
Path=c:\data.mdb
[Database] signifies the start of the section called "Database".
Path is the entry called "Path".
Within the section you can have whatever entries you like. For example, you may have the following entries:
[Database]
Server=\\server1\c\data.mdb
Client=c:\data.mdb
You can add more sections if you want, and you can repeat entry names IN DIFFERENT SECTIONS, BUT NOT IN THE SAME SECTION.
Simon