VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "INIFile"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit

Private Declare Function GetPrivateProfileSectionNames Lib "kernel32" 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 WritePrivateProfileSection Lib "kernel32" Alias "WritePrivateProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String, 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 WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
Private Declare Function WriteProfileSection Lib "kernel32" Alias "WriteProfileSectionA" (ByVal lpAppName As String, ByVal lpString As String) As Long
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

Dim lPath As String
Dim lPrivateINI As Boolean

Public Property Get Path() As String
    Path = lPath
    lPrivateINI = True
End Property

Public Property Get PrivateINI() As Boolean
    PrivateINI = lPrivateINI
End Property

Public Property Let PrivateINI(ByVal vNewValue As Boolean)
    lPrivateINI = vNewValue
End Property

Public Property Let Path(ByVal vNewValue As String)

If Dir(Path) = "" Then
    Err.Description = "File not found: " & vNewValue
    Err.Raise 53
Else
    lPath = vNewValue
End If

End Property

Public Function WriteString(Section As String, Key As String, Value As String) As Integer

If lPrivateINI Then
    WriteString = WritePrivateProfileString(Section, Key, Value, lPath)
Else
    WriteString = WriteProfileString(Section, Key, Value)
End If

End Function

Public Function GetString(Section As String, Key As String, Default As String) As String

Dim A As String

A = Space(255)

If lPrivateINI Then
    GetPrivateProfileString Section, Key, Default, A, 255, lPath
Else
    GetProfileString Section, Key, Default, A, 255
End If

GetString = A

End Function

Public Function WriteSection(Section As String, Contents As String)

If lPrivateINI Then
    WriteSection = WritePrivateProfileSection(Section, Contents, lPath)
Else
    WriteSection = WriteProfileSection(Section, Contents)
End If

End Function

Public Function GetSectionContents(Section As String) As String

Dim A As String * 2048

If lPrivateINI Then
    If GetPrivateProfileSection(Section, A, 2048, lPath) = 0 Then Exit Function
Else
    If GetProfileSection(Section, A, 2048) = 0 Then Exit Function
End If

GetSectionContents = A

End Function

Public Function GetKeysInSection(Section As String) As Variant

Dim A%, All$, Buff

All = GetSectionContents(Section)
Buff = Split(All, Chr(13))

For A = LBound(Buff) To UBound(Buff)
    Buff(A) = Left$(Buff(A), InStr(1, Buff(A), "=") - 1)
Next

GetKeysInSection = Buff

End Function

Public Function GetSectionNames() As Variant

Dim szBuf As String, Length As Integer

If lPrivateINI = False Then
    GetSectionNames = Null
    Exit Function
End If

szBuf = Space(1024)
Length = GetPrivateProfileSectionNames(szBuf, 1024, lPath)
szBuf = Left$(szBuf, Length)
GetSectionNames = Split(szBuf, vbNullChar)

End Function

Private Sub Class_Initialize()

lPrivateINI = True

End Sub
