'参数:SectionName '小节名,前后可有[],也可无
'参数:optDelIncludeSectionName_1 '默认为1,表示同时将小节名删除,为0则保留小节名不删,只删除小节名下的全部Key
'实例:delSectionAllTxtInINIFile "[登录帐户XX]", "S:\帐户.ini" '
' delSectionAllTxtInINIFile "登录帐户XX", "S:\帐户.ini", 0 '保留小节名不删
Public Function delSectionAllTxtInINIFile(SectionName, INIFile, Optional optDelIncludeSectionName_1 = 1)
Dim ColectStr 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$
If Trim$(TmpStr$) = SectionName Then
If optDelIncludeSectionName_1 <> 1 Then
ColectStr = ColectStr & TmpStr$ & vbCrLf '不删小节名
End If
Do While Not EOF(TmpFileNum1)
Line Input #TmpFileNum1, TmpStr$
If TmpStr$ <> "" Then
LsTmpStr$ = Trim$(TmpStr$)
If Left$(LsTmpStr$, 1) = "[" And Right$(LsTmpStr$, 1) = "]" Then '下一节了
ColectStr = ColectStr & TmpStr$ & vbCrLf
Exit Do
End If
Else
ColectStr = ColectStr & TmpStr$ & vbCrLf
End If
Loop
Else
ColectStr = ColectStr & TmpStr$ & vbCrLf
End If
Loop
Close #TmpFileNum1
DeleteFile INIFile
If ColectStr <> "" Then
If Right$(ColectStr, 2) = vbCrLf Then
ColectStr = Left$(ColectStr, Len(ColectStr) - 2)
End If
AppendWriteFile ColectStr, INIFile
End If
End If
End Function