【VB源碼推薦:一個操作Ini文件的類】
'--------cIniFile.cls 代碼----------------
'這里定義了一個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)
'// 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
'--------cIniFile.cls 使用舉例----------------
Dim myIniFile As New cIniFile
'---指定訪問的ini文件
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
'---寫入ini文件
myIniFile.WriteFile "setting", "username", strUser
'---讀出ini文件的數據
' 注意,如果是字符串,則去掉末尾一個字符
' ----flybird@chinaasp.com
strUser = Trim(myIniFile.GetFile("setting", "username"))
strUser = Left(strUser, Len(strUser) - 1)
文章來源于領測軟件測試網 http://www.kjueaiud.com/
版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備10010545號-5
技術支持和業務聯系:info@testage.com.cn 電話:010-51297073
老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月