📄 module1.bas
字号:
If TotalSections(FileName) - 1 < SectionIndexNum Then MsgBox SectionIndexNum & ", not a valid Section Index Number. ~(GetKey2)", vbInformation, "Invalid Index Number.": Exit Function
If NumKeys(FileName, GetSection(FileName, SectionIndexNum)) - 1 < KeyIndexNum Then MsgBox KeyIndexNum & ", not a valid Key Index Number. ~(GetKey2)", vbInformation, "Invalid Index Number.": Exit Function
Counter = -1
Counter2 = -1
Open FileName For Input As #7
Do While Not EOF(7)
Line Input #7, InputData
If InZone Then
If IsKey(InputData) Then
Counter = Counter + 1
If Counter = KeyIndexNum Then
For Looper = 1 To Len(InputData)
If Mid(InputData, Looper, 1) = "=" Then
GetKey2 = KeyName
Exit Do
Else
KeyName = KeyName & Mid(InputData, Looper, 1)
End If
Next Looper
End If
End If
Else
If IsSection(InputData) Then Counter2 = Counter2 + 1
If Counter2 = SectionIndexNum Then InZone = True
End If
Loop
Close #7
End Function
Public Function GetSection(ByVal FileName As String, ByVal SectionIndexNum As Integer) As String
'Returns a section name which is identified by it's indexnumber
'IndexNumbers begin at 0 and increment up
Dim InputData As String
Dim Counter As Integer
If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
If TotalSections(FileName) - 1 < SectionIndexNum Then MsgBox SectionIndexNum & ", not a valid Section Index Number. ~(GetSection)", vbInformation, "Invalid Index Number.": Exit Function
Counter = -1
Open FileName For Input As #8
Do While Not EOF(8)
Line Input #8, InputData
If IsSection(InputData) Then
Counter = Counter + 1
InputData = Right(InputData, Len(InputData) - 1)
InputData = Left(InputData, Len(InputData) - 1)
If Counter = SectionIndexNum Then GetSection = InputData: Exit Do
End If
Loop
Close #8
End Function
Public Function IsKey(ByVal TextLine As String) As Boolean
'This function determines whether or not a line of text is a valid Key (ex. "This=key")
'This returns True or False
Dim Looper As Integer
For Looper = 1 To Len(TextLine)
If Mid(TextLine, Looper, 1) = "=" Then IsKey = True: Exit Function
Next Looper
IsKey = False
End Function
Public Function IsSection(ByVal TextLine As String) As Boolean
'This function determines whether or not a line of text is a
'valid section (ex. "[section]")
'This return's True or False
Dim FirstChar As String, LastChar As String
If TextLine = "" Then Exit Function
FirstChar = Mid(TextLine, 1, 1)
LastChar = Mid(TextLine, Len(TextLine), 1)
If FirstChar = "[" And LastChar = "]" Then IsSection = True Else IsSection = False
End Function
Public Function KeyExists(ByVal FileName As String, ByVal Section As String, ByVal Key As String) As Boolean
'This function determines if a key exists in a given section
'The Section is identified as Text - KeyExists2 identifies Section by its IndexNumber
'This returns True or False
Dim InZone As Boolean
Dim InputData As String
Dim Looper As Integer
If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
If Not SectionExists(FileName, Section) Then MsgBox "Section, " & Section & ", Not Found. ~(KeyExists)" & vbCrLf & "Verify spelling and capitilization is correct. Case-sensative.", vbInformation, "Section Not Found.": Exit Function
Open FileName For Input As #9
Do While Not EOF(9)
Line Input #9, InputData
If InZone Then
If IsKey(InputData) Then
If Left(InputData, Len(Key)) = Key Then
KeyExists = True
Exit Do
End If
ElseIf IsSection(InputData) Then
KeyExists = False
Exit Do
End If
Else
If InputData = "[" & Section & "]" Then InZone = True
End If
Loop
Close #9
End Function
Public Function KeyExists2(ByVal FileName As String, ByVal SectionIndexNum As Integer, ByVal Key As String) As Boolean
'This function determines if a key exists in a given section
'The Section is identified by its IndexNumber
'IndexNumbers begin at 0 and increment up
'This returns True or False
Dim InZone As Boolean
Dim InputData As String
Dim Looper As Integer
Dim Counter As Integer
If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
If TotalSections(FileName) - 1 < SectionIndexNum Then MsgBox SectionIndexNum & ", not a valid Section Index Number. ~(KeyExists2)", vbInformation, "Invalid Index Number.": Exit Function
Counter = -1
Open FileName For Input As #10
Do While Not EOF(10)
Line Input #10, InputData
If InZone Then
If IsKey(InputData) Then
If Left(InputData, Len(Key)) = Key Then
KeyExists2 = True
Exit Do
End If
ElseIf IsSection(InputData) Then
KeyExists2 = False
Exit Do
End If
Else
If IsSection(InputData) Then Counter = Counter + 1
If Counter = SectionIndexNum Then InZone = True
End If
Loop
Close #10
End Function
Public Function SectionExists(ByVal FileName As String, ByVal Section As String)
'This determines if a section exists in a given INI file
'This returns True or False
If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
Dim InputData As String
Open FileName For Input As #11
Do While Not EOF(11)
Line Input #11, InputData
If "[" & Section & "]" = InputData Then SectionExists = True: Exit Do
SectionExists = False
Loop
Close #11
End Function
Public Function GetSectionIndex(ByVal FileName As String, ByVal Section As String) As Integer
'This function is used to get the IndexNumber for a given Section
If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
If Not SectionExists(FileName, Section) Then MsgBox "Section, " & Section & ", Not Found. ~(GetSectionIndex)" & vbCrLf & "Verify spelling and capitilization is correct. Case-sensative.", vbInformation, "Section Not Found.": Exit Function
Dim InputData As String
Dim Counter As Integer
Counter = -1
Open FileName For Input As #12
Do While Not EOF(12)
Line Input #12, InputData
If IsSection(InputData) Then Counter = Counter + 1
If "[" & Section & "]" = InputData Then GetSectionIndex = Counter
Loop
Close #12
End Function
Public Function GetKeyIndex(ByVal FileName As String, ByVal Section As String, ByVal Key As String) As Integer
'This function returns the IndexNumber of a key in a given Section
'The Section is identified as Text - GetKeyIndex2, Section is
'identified by it's IndexNumber
'IndexNumbers start at 0 and increment up
If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
If Not SectionExists(FileName, Section) Then MsgBox "Section, " & Section & ", Not Found. ~(GetKeyIndex)" & vbCrLf & "Verify spelling and capitilization is correct. Case-sensative.", vbInformation, "Section Not Found.": Exit Function
If Not KeyExists(FileName, Section, Key) Then MsgBox "Key, " & Key & ", Not Found. ~(GetKetIndex)" & vbCrLf & "Verify spelling and capitilization is correct. Case-sensative.", vbInformation, "Key Not Found.": Exit Function
Dim InputData As String
Dim InZone As Boolean
Dim Counter As Integer
Counter = -1
Open FileName For Input As #13
Do While Not EOF(13)
Line Input #13, InputData
If InZone Then
If IsKey(InputData) Then
Counter = Counter + 1
If Left(InputData, Len(Key)) = Key Then
GetKeyIndex = Counter
Exit Do
End If
ElseIf IsSection(InputData) Then
Exit Do
End If
Else
If "[" & Section & "]" = InputData Then InZone = True
End If
Loop
Close #13
End Function
Public Function GetKeyIndex2(ByVal FileName As String, ByVal SectionIndexNum As Integer, ByVal Key As String) As Integer
'This function returns the IndexNumber of a key in a given Section
'The Section is identified by it's IndexNumber
'IndexNumbers start at 0 and increment up
If Dir(FileName) = "" Then MsgBox FileName & " not found.", vbCritical, "File Not Found": Exit Function
If TotalSections(FileName) - 1 < SectionIndexNum Then MsgBox SectionIndexNum & ", not a valid Section Index Number. ~(GetKeyIndex2)", vbInformation, "Invalid Index Number.": Exit Function
If Not KeyExists(FileName, GetSection(FileName, SectionIndexNum), Key) Then MsgBox "Key, " & Key & ", Not Found. ~(GetKetIndex2)" & vbCrLf & "Verify spelling and capitilization is correct. Case-sensative.", vbInformation, "Key Not Found.": Exit Function
Dim InputData As String
Dim Counter As Integer
Dim Counter2 As Integer
Dim InZone As Boolean
Counter = -1
Counter2 = -1
Open FileName For Input As #14
Do While Not EOF(14)
Line Input #14, InputData
If InZone Then
If IsKey(InputData) Then
Counter = Counter + 1
If Left(InputData, Len(Key)) = Key Then
GetKeyIndex2 = Counter
Exit Do
End If
ElseIf IsSection(InputData) Then
Exit Do
End If
Else
If IsSection(InputData) Then Counter2 = Counter2 + 1
If Counter2 = SectionIndexNum Then InZone = True
End If
Loop
Close #14
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -