ini文件处理
已经知道ini文件的主键名,如何得知其主键下面所有的副键名,谢谢。 问题点数:0、回复次数:1Top
1 楼songyaowu(不以分多而蹭之;不因分少而不答; www.vb99.com)回复于 2005-06-02 08:45:24 得分 0
'*****************************************************
' 读取*.ini文件中的所有项目
'=====================================================
' lpFilename - *.ini文件名
' SectionArry() - 存储返回的项目
'=====================================================
' 函数返回数组的最大下标值。(数组最小下标值为0)
' 若没有找到任何值则函数返回-1
'*****************************************************
Public Function GetPrivateProfileAllSection(SectionArry() As String, lpFileName As String) As Long
Dim s As String
Dim i, Max As Integer
s = Space(1024)
GetPrivateProfileString 0&, 0&, "", s, 1024, lpFileName
SectionArry = Split(s, Chr(0))
Max = UBound(SectionArry) - 2
If Max >= 0 Then
ReDim Preserve SectionArry(Max)
End If
GetPrivateProfileAllSection = Max
End Function
'***********************************************************************************
' 读取*.ini文件中指定小节下的所有关键字和值,每个关键字和值在数组中的位置一一对应
'===================================================================================
' pFile - *.ini文件名
' KeyString - 小节名
' KeyArry() - 存储返回的所有关键字
' ValueArry() - 存储返回的所有键值
'===================================================================================
' 函数返回关键字和键值数组的最大下标值。(数组最小下标值为0)
'***********************************************************************************
Public Function GetPrivateProfileSectionKeyValue(SectionName As String, pFile As String, KeyArry() As String, ValueArry() As String) As Long
Dim TempStr As String
Dim i, j, Max As Integer
Dim Rcode As Integer
Dim StringArry() As String
Dim l As Long
TempStr = Space(32676)
l = GetPrivateProfileSection(SectionName, TempStr, 32676, pFile)
If l <> 0 Then
TempStr = RTrim$(TempStr)
TempStr = Replace(TempStr, "=", Chr(0))
StringArry = Split(TempStr, Chr(0))
Max = UBound(StringArry) - 2
Rcode = (Max - 1) / 2
ReDim KeyArry(Rcode)
ReDim ValueArry(Rcode)
j = 0
For i = 0 To Rcode
KeyArry(i) = StringArry(j)
j = j + 1
ValueArry(i) = StringArry(j)
j = j + 1
Next
Erase StringArry
Else
Rcode = -1
End If
GetPrivateProfileSectionKeyValue = Rcode
End Function
完整工程下载: http://www.vb99.com/loaddown.asp?tid=1&pathid=6&Filenames=40Top




