1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
| Private Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Private 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
Private Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, ByVal lpFileName As String) As Long
Private Const CONFIG_FILE = "C:\Users\client\Documents\Test.ini"
Sub Ecrire_Section_Clef_Valeur()
Dim Section As String
Dim Clef As String
Dim sValeur As Variant
Section = "Section3"
Clef = "Clef10"
sValeur = 12345
xx = WriteINI(Section, Clef, sValeur)
End Sub
Sub Lire_Valeur()
Dim Section As String
Dim Clef As String
Section = "Section3"
Clef = "Clef10"
xx = GetINIString(Section, Clef)
End Sub
Public Function GetINIString(ByVal Section As String, ByVal Clef As String) As String
Dim sBuf As String * 256
Dim lBuf As Long
lBuf = GetPrivateProfileString(Section, Clef, "", sBuf, Len(sBuf), CONFIG_FILE)
GetINIString = Left$(sBuf, lBuf)
End Function
Public Function WriteINI(ByVal Section As String, ByVal Clef As String, ByVal sValeur As String) As String
WritePrivateProfileString Section, Clef, sValeur, CONFIG_FILE
End Function |
Partager