Option Explicit Private Declare Function GetProfileSection Lib "kernel32" Alias "GetProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long Private Declare Function GetProfileString Lib "kernel32" Alias "GetProfileStringA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal lpDefault As String, ByVal lpReturnedString As String, ByVal nSize As Long) As Long Private Declare Function GetProfileInt Lib "kernel32" Alias "GetProfileIntA" (ByVal lpAppName As String, ByVal lpKeyName As String, ByVal nDefault As Long) As Long Private Declare Function WriteProfileSection Lib "kernel32" Alias "WriteProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String) As Long Private Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long Private Declare Function GetPrivateProfileSectionNames Lib "kernel32.dll" Alias "GetPrivateProfileSectionNamesA" (ByVal lpszReturnBuffer As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Private Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long Private 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 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 Any, ByVal lpString As Any, ByVal lpFileName As String) As Long Private Declare Function WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, ByVal lpFileName As String) As Long Private Sub Form_Load() Dim buffer As String Dim ret As Long Dim i As Long Dim Records() As String Dim INIfile As String buffer = String(32767, vbNullChar) ret = GetProfileSection("MCI Extensions", buffer, 32767) Debug.Print "GetProfileSection returned:", ret buffer = Left(buffer, ret) ' trim the null characters at the end Records = Split(buffer, vbNullChar) If UBound(Records) > 0 Then For i = 0 To UBound(Records) Debug.Print Records(i) Next i End If WriteProfileSection "Example", "KeyString=KeyValue" & Chr(0) & _ "KeyString2=KeyValue2" & Chr(0) & Chr(0) ' create in the Example section a key Age , value 20 WriteProfileString "Example", "Age", "20" ' try to read back the number ret = GetProfileInt("Example", "Age", 0) Debug.Print "GetProfileInt=", ret buffer = String(20, vbNullChar) 'trying to read the same value as a string using GetProfileString ret = GetProfileString("Example", "Age", "", buffer, 20) If ret > 0 Then buffer = Left(buffer, ret) Debug.Print "GetProfileString=", buffer INIfile = App.Path & IIf(Right(App.Path, 1) = "\", "", "\") & "Example.ini" WritePrivateProfileSection "Section1", "Key1=Value1", INIfile WritePrivateProfileString "Section1", "StringKey", "StringValue", INIfile WritePrivateProfileString "Section1", "NumericKey", "100", INIfile WritePrivateProfileSection "Section2", "Key2=Value2", INIfile buffer = String(32767, vbNullChar) ret = GetPrivateProfileSection("Section1", buffer, 32767, INIfile) buffer = Left(buffer, ret) Records = Split(buffer, Chr(0)) Debug.Print "Values in Section1:" If UBound(Records) > 0 Then For i = 0 To UBound(Records) Debug.Print Records(i) Next i End If buffer = String(200, Chr(0)) ret = GetPrivateProfileString("Section1", "StringKey", "", buffer, 200, INIfile) buffer = Left(buffer, ret) Debug.Print "GetPrivateProfileString:", buffer ret = GetPrivateProfileInt("Section1", "NumericKey", 0, INIfile) Debug.Print "GetPrivateProfileInt:", ret buffer = String(32767, Chr(0)) ret = GetPrivateProfileSectionNames(buffer, 32767, INIfile) buffer = Left(buffer, ret) Records = Split(buffer, Chr(0)) Debug.Print "Sections:" If UBound(Records) > 0 Then For i = 0 To UBound(Records) Debug.Print Records(i) Next i End If End Sub