|
下面就是我用的。
- Dim objconfig ,v_file
- Public Function openconfig(file)
- v_file = file
- Set objconfig = CreateObject("msxml2.domdocument")
- If CreateObject("scripting.filesystemobject").FileExists(v_file) Then
- objconfig.load file
- Else
- objconfig.loadXML "<root><param></param></root>"
- End If
- End Function
- Public Function getconfig(name)
- Set tmp = objconfig.selectSingleNode("/root/param/"&name)
- If tmp Is Nothing Then
- getconfig = ""
- Else
- getconfig = tmp.text
- End If
- End Function
- Public Function setconfig(name,value)
- Set tmp = objconfig.selectSingleNode("/root/param/"&name)
- If tmp Is Nothing Then
- Set newelement = objconfig.createElement(name)
- newelement.text = value
- objconfig.selectSingleNode("/root/param").appendChild newelement
- Else
- tmp.text = value
- End If
- objconfig.save v_file
- End Function
- ''######## 使用例子 ##########
- openconfig "mm.xml"
- setconfig "testname","test01"
- MsgBox getconfig("testname")
复制代码 |
|