La cosa è semplice, devi:
1) dichiarare le api di windows che servono alla modifica/lettura dei file INI:
Codice:
' -----------------------------------------------------------------
'Funzioni per la Gestione dei Files .INI delle Impostazioni
' -----------------------------------------------------------------
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
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
2) creare le funzioni di lettura e scrittura, ad esempio:
Codice:
Public Function INIRead(File As String, Section As String, Item As String) As String
Dim sBuf As String
Dim iRC As Integer
sBuf = Space(1023)
iRC = GetPrivateProfileString(Section, Item, "Not Found", sBuf, 1023, App.Path + "/" + File)
sBuf = Left$(sBuf, iRC)
If StrComp(sBuf, "Not Found") = 0 Then
INIRead = vbNullString
Else
INIRead = sBuf
End If
End Function
Public Sub INIWrite(File As String, Section As String, Item As String, ItemValue As String)
WritePrivateProfileString Section, Item, ItemValue, App.Path + "/" + File
End Sub
queste cose dette puoi ad esempio metterle in un Modulo.
Successivamente dovrai solo richiamare una delle due funzioni per gestire il file INI, ad esempio:
LETTURA:
INIRead("nome_file.ini", Sezione , valore_da_leggere)
SCRITTURA:
INIWrite "nome_file.ini", Sezione, valore_da_Scrivere, valore
tutto qui