VB源碼推薦:一個(gè)操作Ini文件的類

字號(hào):

【VB源碼推薦:一個(gè)操作Ini文件的類】
    ´--------cIniFile.cls 代碼----------------
    ´這里定義了一個(gè)cIniFile類
    Option Explicit
    ´// Private member that holds a reference to
    ´// the path of our ini file
    Private strInI As String
    ´// Win API Declares
    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 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 Function MakePath(ByVal strDrv As String, _
     ByVal strDir As String) As String
    ´// Makes an INI file: Guarantees a sub dir
    Do While Right$(strDrv, 1) = "\"
     strDrv = Left$(strDrv, Len(strDrv) - 1)
    Loop
    Do While Left$(strDir, 1) = "\"
     strDir = Mid$(strDir, 2)
    Loop
    ´// Return the path
    MakePath = strDrv & "\" & strDir
    End Function
    Public Sub CreateIni(strDrv As String, strDir As String)
    ´// Make a new ini file
    strInI = MakePath(strDrv, strDir)
    End Sub
    Public Sub WriteFile(strSection As String, _
    strKey As String, _
    strValue As String)