'参数:SectionName '小节名
'参数:INIFile 'ini文件
'参数:optIncludeSectionName_0 '默认=0,不连带小节名返回,只返回其下内容,=1返回串中包括小节名(第一行),但读不到任何设置时,就不会只返回小节名而返回空。
'实例:Print GetSectionAllTxtInINIFile("[登录帐户]", "E:\帐户.ini", 1)
' Print GetSectionAllTxtInINIFile("[全系统]", "E:\全系统.txt")
Public Function GetSectionAllTxtInINIFile(SectionName, INIFile, Optional optIncludeSectionName_0 = 0)
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 Left$(LsTmpStr$, 1) = "[" And Right$(LsTmpStr$, 1) = "]" Then '下一节了
Exit Do
Else
GetSectionAllTxtInINIFile = GetSectionAllTxtInINIFile & TmpStr$ & vbCrLf
End If
Loop
Exit Do
End If
Loop
Close #TmpFileNum1
GetSectionAllTxtInINIFile = RemoveEmpityLineInStr(GetSectionAllTxtInINIFile, 1, 1, 1, 1)
If optIncludeSectionName_0 = 1 And GetSectionAllTxtInINIFile <> "" Then
GetSectionAllTxtInINIFile = SectionName & vbCrLf & GetSectionAllTxtInINIFile
End If
End If
End Function