读取/写入当前文件夹中 Parameter.ini 的指定行。
Public Function ReadParameter(pRow) As String
On Error Resume Next
'读取配置文件的指定行
Dim Str As String, LS_Content() As String
Dim LogCount As Long
Dim i As Long
Str = Empty
Dim cLine(30) As String, pLine(30) As String
Open App.Path & "/Parameter.ini" For Input As #1
Str = StrConv(InputB(LOF(1), #1), vbUnicode) '将文件内容附给变量 Str
Close #1
LS_Content = Split(Str, vbCrLf) '将每一行的信息放入数组
LogCount = UBound(LS_Content)
Str = LS_Content(0)
For i = 1 To pRow - 1
If i = pRow - 1 And LS_Content(i) <> Empty Then
cLine(i) = InStr(LS_Content(i), "=") - 1 '获取等号后的参数值
pLine(i) = Mid(LS_Content(i), cLine(i) + 2)
ReadParameter = pLine(i)
End If
Next i
''eg
'CBool(ReadParameter(pRow)) = True
End Function
Public Sub WriteParameter(pRow As Integer, pContent As String)
On Error Resume Next
'写入配置文件的指定行
Dim Str As String, LS_Content() As String
Dim LogCount As Long
Dim i As Long
Str = Empty
Open App.Path & "/Parameter.ini" For Input As #1
Str = StrConv(InputB(LOF(1), #1), vbUnicode) '将文件内容附给变量 Str
Close #1
LS_Content = Split(Str, vbCrLf) '将每一行的信息放入数组
LS_Content(pRow - 1) = pContent '更改第二行.
LogCount = UBound(LS_Content)
Str = LS_Content(0)
For i = 1 To LogCount
If LS_Content(i) <> Empty Then Str = Str & vbCrLf & LS_Content(i)
Next i
Open App.Path & "/Parameter.ini" For Output As #1
Print #1, Trim(Str) '写入内容
Close #1
''eg
'WriteParameter(pRow)
End Sub
记录一下,用于读取和写入.INI文件的指定行。