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 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 ReadINI(strKey as string, _ strName as string) As String Dim intLen as integer Dim strText as string, strIniFile as string ' Define INI Path strIniFile = <Path to your ini file> & "\myfile.ini" ' read information from ini file and check for errors strText = Space(80) intLen = GetPrivateProfileString(strKey, strName, "", _ strText, Len(strText), strIniFile) If intLen > -1 Then strText = Left(strText, intLen) Else MsgBox "INI File error" End End If ReadINI = strText End Function Public Sub WriteINI(strKey as string, strName as string _ strText as string) Dim intLen as integer Dim strIniFile as string ' Define INI Path strIniFile = <Path to your ini file> & "\myfile.ini" ' Write to ini intLen = WritePrivateProfileString(strKey, strName, _ strText, strIniFile) End Sub 'Now for example, let's say I have inside my ini file 'the following: [Settings] LeftSpeaker=On RightSpeaker=On 'To read the setting for the left speaker, 'use the following code: strLeftSpeaker = ReadINI("Settings", "LeftSpeaker") 'The variable "strLeftSpeaker" would then be "On". 'To change the value of "LeftSpeaker" in "Settings" 'in your ini file,use the following code: Call WriteINI("Settings", "LeftSpeaker", "Off") 'The value of "LeftSpeaker" will now be set to "Off" 'in your ini file. |