配置文件:
源码:
Dim Co As Object '设为全局变量 Function 读取cfg() As Boolean Dim strcfg As String strcfg = "D:a.cfg" If Dir(strcfg, vbDirectory) = "" Then MsgBox "错误:配置文件不存在!" & Chr(10) & strcfg 'Chr(10)换行符 Exit Function End If Set Co = CreateObject("Scripting.Dictionary") Dim a As Variant Dim s As String Open strcfg For Input As #1 While Not EOF(1) Line Input #1, s If Len(s) > 2 Then If Not InStr(s, "##") Then If InStr(s, "=") Then a = Split(s, "=") Co.Add a(0), a(1) ''Debug.Print a(0) & "=" & a(1) End If End If End If Wend Close #1 End Function
用法:
Sub 显示() Debug.Print Co("A001") End Sub