VB Code:
  1. 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
  2. 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
  3. Public Sub WriteINI(wiSection As String, wiKey As String, wiValue As String, wiFile As String)
  4.     WritePrivateProfileString wiSection, wiKey, wiValue, App.Path & "\" & wiFile
  5. End Sub
  6. Public Function ReadINI(riSection As String, riKey As String, riFile As String, riDefault As String)
  7.     Dim sRiBuffer As String
  8.     Dim sRiValue As String
  9.     Dim sRiLong As String
  10.     Dim INIFile As String
  11.     INIFile = App.Path & "\" & riFile
  12.     If Dir(INIFile) <> "" Then
  13.         sRiBuffer = String(255, vbNull)
  14.         sRiLong = GetPrivateProfileString(riSection, riKey, Chr(1), sRiBuffer, 255, INIFile)
  15.         If Left$(sRiBuffer, 1) <> Chr(1) Then
  16.             sRiValue = Left$(sRiBuffer, sRiLong)
  17.             If sRiValue <> "" Then
  18.                 ReadINI = sRiValue
  19.             Else
  20.                 ReadINI = riDefault
  21.             End If
  22.         Else
  23.             ReadINI = riDefault
  24.         End If
  25.     Else
  26.         ReadINI = riDefault
  27.     End If
  28. End Function