INI文件读取操作
2016-09-19 11:58:24| 分类:
默认分类
| 标签:
|举报
|字号大中小 订阅
Declare Function GetPrivateProfileSection Lib "kernel32" Alias "GetPrivateProfileSectionA" _
(ByVal lpAppName As String, ByVal lpReturnedString As String, ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function GetPrivateProfileSectionNamesA Lib "kernel32.dll" (ByVal szValue$, ByVal nSize&, ByVal szFileName$) As Long
Declare Function GetPrivateProfileString Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal lpApplicationName As String, _
lpKeyName As Any, ByVal lpDefault As String, _
ByVal lpRetunedString As String, _
ByVal nSize As Long, ByVal lpFileName As String) As Long
Declare Function WritePrivateProfileString Lib "kernel32" Alias "WritePrivateProfileStringA" _
(ByVal lpApplicationName As String, ByVal lpKeyName As String, ByVal lpString As String, _
ByVal lpFileName As String) As Long
'*************************************************************************
'读取INI中所有Section名
'*************************************************************************
Function GetSectionsName(sPath) As String()
Dim szBuffer$, nLen%
Dim strTmp As String
Dim sArray() As String
Dim i As Integer
Dim nStart As Integer
Dim nEnd As Integer
szBuffer = String(1024, 0)
Call GetPrivateProfileSectionNamesA(szBuffer, 1024, sPath)
strTmp = szBuffer
i = 1
Do While strTmp <> ""
nStart = nEnd + 1
nEnd = InStr(nStart, szBuffer, vbNullChar)
strTmp = Mid$(szBuffer, nStart, nEnd - nStart)
If Len(strTmp) > 0 Then
ReDim Preserve sArray(1 To i)
sArray(i) = strTmp
i = i + 1
End If
Loop
GetSectionsName = sArray
End Function
'读取Section中的所有Item名
Function GetIniItems(sSection As String, FileName As String) As String()
Dim strReturn As String * 32767
Dim strTmp As String
Dim nStart As Integer
Dim nEnd As Integer
Dim i As Integer
Dim sArray() As String
Call GetPrivateProfileSection(sSection, strReturn, Len(strReturn), FileName)
strTmp = strReturn
i = 1
Do While strTmp <> ""
nStart = nEnd + 1
nEnd = InStr(nStart, strReturn, vbNullChar)
strTmp = Mid$(strReturn, nStart, nEnd - nStart)
If Len(strTmp) > 0 Then
ReDim Preserve sArray(1 To i)
sArray(i) = strTmp
i = i + 1
End If
Loop
GetIniItems = sArray
End Function
'读取Item的值
Function GetIniItemKey(sSectionName As String, KeyName As String, FileName As String) As String
Dim RetStr As String
RetStr = String(10000, Chr(0))
GetIniItemKey = Left(RetStr, GetPrivateProfileString(sSectionName, ByVal KeyName, "", RetStr, Len(RetStr), FileName))
End Function
'写入INI
WritePrivateProfileString “Section”,"Item","Keys","Path"
'删除Section
WritePrivateProfileString Section, vbNullString, vbNullString, FileName
‘删除Item
WritePrivateProfileString Section, KeyName, vbNullString, FileName
评论这张
转发至微博
转发至微博
评论