sinat_34316164
2016-06-19 09:10
采纳率: 0%
浏览 1.8k

vb6.0读取xml报错,提示对象变量或with块变量未设置

我是VB初学者求大神指教,谢谢!
以下是代码
Private Sub Form_Load()
Dim xml_document As DOMDocument
Dim values_node As IXMLDOMNode
Dim XlmPath As String
' Load the document.
Set xml_document = New DOMDocument
XlmPath = App.Path & "Value.xml"
xml_document.Load (XlmPath)
' If the file doesn't exist, then
' xml_document.documentElement is Nothing.
If xml_document.Load(XlmPath) Then
' The file doesn't exist. Do nothing.
Exit Sub
End If
' Find the Values section.
Set values_node = xml_document.selectSingleNode("Values")
' Read the saved values.
txtFirstName.Text = GetNodeValue(values_node, "FirstName", "???")
txtLastName.Text = GetNodeValue(values_node, "LastName", "???")
txtStreet.Text = GetNodeValue(values_node, "Street", "???")
txtCity.Text = GetNodeValue(values_node, "City", "???")
txtState.Text = GetNodeValue(values_node, "State", "???")
txtZip.Text = GetNodeValue(values_node, "Zip", "???")
Text1.Text = txtFirstName.Text + "" + txtLastName.Text + "" + txtStreet.Text
End Sub

Private Function GetNodeValue(ByVal node As IXMLDOMNode, ByVal node_name As String, Optional ByVal default_value As String = "") As String
Dim value_node As IXMLDOMNode
Set value_node = node.selectSingleNode(".//" & node_name)
If value_node Is Nothing Then
GetNodeValue = default_value
Else
GetNodeValue = value_node.Text
End If
End Function

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • threenewbee 2016-06-19 09:17

    有没有添加对xml库的引用?

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题