>Any sample on reading an INI file?
>
>I would like to read some parameters that I created in a small INI file.
Give this sample a try:
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
Public Function ReadFromINI(ByVal pSection As String, _
ByVal pKey As String, _
ByVal pDefault As String, _
ByVal pPath As String _
) As String
Dim lngReturn As Long
Dim strReturn As String
strReturn = String$(200, 0)
lngReturn = GetPrivateProfileString(pSection, pKey, pDefault, strReturn, Len(strReturn), pPath)
ReadFromINI = Left$(strReturn, lngReturn)
End Function
You can call it this way:
MyVariable = ReadFromINI("ODBC", "DB-SERVER", "GAA-ERREUR", App.Path & "\GAA.INI")
You can also take a look at WritePrivateProfileString function that write to an INI file.
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com