VB source Recommendations: a document type operation Ini
[VB source Recommendations: a document type operation - Ini
'——– CIniFile.cls code —————-
'Here the definition of a 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)
L oop
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)
'/ / Write to strINI
WritePrivateProfileString strSection, _
StrKey, strValue, strInI
End Sub
Public Function GetFile (strSection As String, _
StrKey As String) As String
Dim strTmp As String
Dim lngRet As String
StrTmp = String $ (100, Chr (32))
LngRet = GetPrivateProfileString (strSection, _
StrKey, "", strTmp, _
Len (strTmp), strInI)
GetFile = strTmp
End Function
Public Property Let INIFile (ByVal New_IniPath As String)
'/ / Sets the new ini path
StrInI = New_IniPath
End Property
Public Property Get INIFile () As String
'/ / Returns the current ini path
INIFile = strInI
End Property
For example'——– cIniFile.cls use —————-
Dim myIniFile As New cIniFile
'— Designated visit ini files
If Len (App.Path)> 3 Then
'Under disk root dir, eg: "C: \"
MyIniFile.INIFile App.Path & = "\ setting.ini"
Else
MyIniFile.INIFile App.Path & = "setting.ini"
End If
'- Into the ini files
MyIniFile.WriteFile "setting", "username", strUser
'— Read ini file data
'Remember, if the string is removed at the end of a character
'- Flybird @ china ASP. Com
StrUser = Trim (myIniFile.GetFile ( "setting", "username"))
StrUser = Left (strUser, Len (strUser) - 1)








0 Comments to “VB source Recommendations: a document type operation Ini”
No Comments. Send your comment.
Leave a Reply
You must be logged in to post a comment.