'**************************************************************************************************************
'返回:键名1``键名2``......``键名X(以``分隔)
'示例:Print EnumAllKeysInINISection("帐户", "E:\XX.ini")
'返回:0``1``2``3``4``5``6``7``8``9``10``11``12``13``14``15``16......
'后面使用可以用以下格式:
'SectionArray = Split(函数返回值, "``")
'For lngXX = 0 To UBound(SectionArray)
' Print SectionArray (lngXX)
'Next
Public Function EnumAllKeysInINISection(SectionName, INIFile) As String
If FileExist(INIFile) Then
If Left$(SectionName, 1) <> "[" And Right$(SectionName, 1) <> "]" Then
SectionName = "[" & SectionName & "]"
End If
TmpFileNum1 = FreeFile
Open INIFile For Input As #TmpFileNum1
Do While Not EOF(TmpFileNum1)
Line Input #TmpFileNum1, TmpStr$
LsTmpStr$ = Trim$(TmpStr$)
If LsTmpStr$ = SectionName Then
Do While Not EOF(TmpFileNum1)
Line Input #TmpFileNum1, TmpStr$
LsTmpStr$ = Trim$(TmpStr$)
If InStr(TmpStr$, "=") > 0 Then '含有 = 说明是键
EnumAllKeysInINISection = EnumAllKeysInINISection & Left$(TmpStr$, InStr(TmpStr$, "=") - 1) & "``"
ElseIf Left$(LsTmpStr$, 1) = "[" And Right$(LsTmpStr$, 1) = "]" Then '下一节了
Exit Do
End If
Loop
Exit Do
End If
Loop
'删除最后的两个"``"
If EnumAllKeysInINISection <> "" Then
EnumAllKeysInINISection = Left$(EnumAllKeysInINISection, Len(EnumAllKeysInINISection) - 2)
End If
Close #TmpFileNum1
End If
End Function