- ' 读INI文件
- strIniFile = ".\test.inf"
- strBIOS = ReadINI(strIniFile, "Strings", "BIOS")
- strTIDS = ReadINI(strIniFile, "Strings", "TIDS")
- MsgBox "BIOS = " & strBIOS & vbCrLf & "TIDS = " & strTIDS, vbInformation
-
- ' read函数
- Function ReadINI(FilePath, Bar, PrimaryKey)
- Dim fso, sReadLine, i, j, ss
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set IniFile = fso.opentextfile(FilePath, 1,-1)
- Do Until IniFile.atendofstream
- sReadLine = IniFile.readline
- If sReadLine = "" Then
- IniFile.skipline
- ElseIf Trim(sReadLine) = "[" & Bar & "]" Then '找到小节名
- '查找该小节名下的键名
- Do Until IniFile.atendofstream
- sReadLine = IniFile.readline '读取小节名后的行
- j = InStr(sReadLine, "=")
- If j > 0 Then '小节名后的文本行存在
- If InStr(Left(sReadLine, j), PrimaryKey) > 0 Then '从"="左边字符串找到键名
- ss = Trim(Right(sReadLine, Len(sReadLine) - InStr(sReadLine, "="))) '读取等号后的部分
- Exit Do
- End If
- End If
- Loop
- End If
- Loop
- IniFile.Close
- Set fso = Nothing
- ReadINI = ss
- End Function
复制代码
|