【VBA】读取配置文件存入字典型变量中
2024-09-08 04:19:37
配置文件:
源码:
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
最新文章
- Bluemix中国版体验(一)
- linux mail 使用外部邮箱地址发邮件
- opencv 简单模糊和高斯模糊 cvSmooth
- Android studio 快捷添加构造方法以及set与get
- python模块调用
- 【Android】Android之Action Bar
- linux - 创建用户
- Partition List ——LeetCode
- Bootstrap表格的使用
- BroadcastReceiver总结
- Cocos2d-x源代码解析(1)——地图模块(3)
- Revenge of GCD HDU5019
- vs设计界面出现“建控件时出错 响应在此上下文中不可用”
- 安卓服务Service详解
- [Ynoi2018]五彩斑斓的世界
- springboot-01 helloworld
- Windows 10中设置自动登录
- python-随机操作(random)
- position fixed 居中
- Python 逗号的几种作用