读写ini文件的类

糊涂无品 2020-12-20 01:37:46
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 String) As Long
Private Declare Function GetPrivateProfileString _
Lib "kernel32" Alias "GetPrivateProfileStringA" _
(ByVal lpApplicationName As Any, _
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
Do While Right$(strDrv, 1) = ""
strDrv = Left$(strDrv, Len(strDrv) - 1)
Loop
Do While Left$(strDir, 1) = ""
strDir = Mid$(strDir, 2)
Loop
MakePath = strDrv & "" & strDir
End 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

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)
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, Chr(0) & Chr(0)) - 1)
strArray = Split(strTmp, Chr(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, Chr(0) & Chr(0)) - 1)
strArray = Split(strTmp, Chr(0))
End Sub
...全文
68 回复 打赏 收藏 举报
写回复
回复
切换为时间正序
请发表友善的回复…
发表回复
相关推荐
发帖
非技术类
加入

727

社区成员

VB 版八卦、闲侃,联络感情地盘,禁广告帖、作业帖
社区管理员
  • 非技术类社区
申请成为版主
帖子事件
创建了帖子
2020-12-20 01:37
社区公告
暂无公告