Private Sub Class_Initialize()
IniFileName = vbNullString
ErrorMsg = vbNullString
End Sub
Private Function IsINIFileExist()
If IniFileName = vbNullString Then
ErrorMsg = "No INI file exist"
IsINIFileExist = False
Exit Function
End If
IsINIFileExist = True
End Function
Public Sub SetINIPath(strFilePathName)
IniFileName = Trim(strFilePathName)
End Sub
Public Function WriteKey(Section, key, Value)
WriteKey = False
If Not IsINIFileExist() Then
Exit Function
End If
If CInt(Extern.WritePrivateProfileStringA(Section, key, Value, IniFileName)) = 0 Then
ErrorMsg = "Failed to write INI file"
Exit Function
End If
WriteKey = True
End Function
Public Function ReadKey(Section, key, Size)
Dim strKeyValue
ReadKey = vbNullString
If Not IsINIFileExist() Then
Exit Function
End If
strKeyValue = Space(Size)
If CInt(Extern.GetPrivateProfileStringA(Section, key, vbNullString, strKeyValue, Size, IniFileName)) > 0 Then
ReadKey = Trim(strKeyValue)
Else
ErrorMsg = "Can't find the value for key(" & key & ") in Section [" & Section & "]."
End If