Home > Software engineering >  Read and write ini file class
Read and write ini file class

Time:12-21

Option Explicit
Private strInI As String
Private Declare Function WritePrivateProfileString _
Lib "kernel32" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String, _
ByVal lpKeyName As Any, _
ByVal lpString As Any, _
ByVal lpFileName As Long As String)
Private Declare Function GetPrivateProfileString _
Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As Any, _
ByVal lpKeyName As Any, _
As ByVal lpDefault String, _
ByVal lpReturnedString As String, _
ByVal nSize As Long, _
ByVal lpFileName As Long As String)
Private Function MakePath (ByVal strDrv As String, _
ByVal strDir As String) As String
The Do While Right $(strDrv, 1)=""
StrDrv=Left $(strDrv, Len (strDrv) - 1)
Loop
The Do While Left $(strDir, 1)=""
StrDir=Mid $(strDir, 2)
Loop
MakePath=strDrv & "" & strDir
End the Function
Public Sub CreateIni (strDrv As String, strDir As String)
StrInI=MakePath (strDrv strDir)
End Sub

Public Sub WriteFile (strSection As String, _
StrKey As String, _
StrValue As String)
WritePrivateProfileString strSection, _
StrKey strValue, strInI
End Sub

The Public Function GetFile (strSection As String, _
StrKey As String) As String
Dim strTmp As String
Dim lngRet As String
StrTmp=String $(100, CRH (32))
LngRet=GetPrivateProfileString (strSection, _
StrKey, "", strTmp, _
Len (strTmp), strInI)
GetFile=strTmp
End the Function
Public Property Let INIFile (ByVal New_IniPath As String)
StrInI=New_IniPath
End Property
Public Property Get INIFile () As String
INIFile=strInI
End Property
Public Sub getAllSection (strArray () As String)
Dim strTmp As String
Dim lngRet As String
StrTmp=Space (256)
LngRet=GetPrivateProfileString (0 &, _
0 &, ", "strTmp, _
256, strInI)
StrTmp=Left (strTmp, InStr (1, strTmp, CRH (0) & CRH (0)) - 1)
StrArray=Split (strTmp, CRH (0))
End Sub
Public Sub getAllKey (strSection As String, strArray () As String)
Dim strTmp As String
Dim lngRet As String
StrTmp=Space (256)
LngRet=GetPrivateProfileString (strSection, _
0 &, ", "strTmp, _
256, strInI)
StrTmp=Left (strTmp, InStr (1, strTmp, CRH (0) & CRH (0)) - 1)
StrArray=Split (strTmp, CRH (0))
End Sub
  • Related