【问题标题】:Getting Error as 'User defined type not defined' in the code在代码中将错误作为“用户定义的类型未定义”
【发布时间】:2016-10-26 08:45:30
【问题描述】:

今天的问候,

您好,我是使用 vb 6.0 的初学者。我正在使用以下代码并获取“未定义用户定义的类型”。代码如下。我得到错误的行被突出显示。请帮助。我应该添加一些引用或组件吗?如果是的话,它会是什么。您的及时和善意的帮助将对我更有帮助

Public Sub LoadDocument() 
    Dim xDoc As MSXML2.DOMDocument
    Set xDoc = New MSXML2.DOMDocument 
    xDoc.async = False 
    xDoc.validateOnParse = False
    If xDoc.Load("C:\Users\284582\Desktop\XML1.xml") Then
            DisplayNode xDoc.ChildNodes, 0 
    End If 
End Sub    

' Error on this line'
Public Sub DisplayNode(ByRef Nodes As MSXML.IXMLDOMNodeList, _
           ByVal Indent As Integer)    

    Dim xNode As MSXML.IXMLDOMNode
    Indent = Indent + 2    
    For Each xNode In Nodes
        If xNode.NodeType = NODE_TEXT Then

            Debug.Print Space$(Indent) & xNode.ParentNode.nodeName & _
                ":" & xNode.NodeValue 
        End If    

        If xNode.HasChildNodes Then   
            DisplayNode xNode.ChildNodes, Indent  
        End If    
    Next xNode   
End sub    

【问题讨论】:

  • VB6 和 VB.NET 在系统基础设施方面是两个不同的东西。你在这里用的是哪一个?
  • 嗨史蒂夫,我正在使用 Visual Basic 6.0

标签: vb6


【解决方案1】:

这是MSXML2.IXMLDOMNodeList,而不是MSXML.IXMLDOMNodeList

【讨论】:

  • 另外他可能应该添加Option Explicit 或者更好的是打开IDE选项以使其在创建模块时自动生成。
【解决方案2】:

您的参考资料中可能缺少该库。试试这个。

手动添加 MSXML2

1. Open MS Access.
2. Database Tools ribbon
3. Visual Basic  ribbon item (icon)
4. Double-click on any module to open it.

5. Tools menu
6. References…
7. Find  Microsoft XML, v6.0. is in the list
    a. If in list but not checked, check it and click [OK].
    b. If not in the list: 
        i. click [Browse…] and add "c:\windows\system32\msxml6.dll"
8. [OK] your way back to the Visual Basic window.
9. Close the Visual Basic Window.  You should be good to go.

以编程方式添加 MSXML2 添加以下子和功能。运行子。如有必要,编辑 sub 以包含路径。

检查库中损坏的引用 改编自Add references programatically

Sub CheckXmlLibrary()
' This refers to your VBA project.
    Dim chkRef As Reference, RetVal As Integer  ' A reference.
    Dim foundWord As Boolean, foundExcel As Boolean, foundXml As Boolean
    foundWord = False
foundExcel = False
    foundXml = False

' Check through the selected references in the References dialog box.
    For Each chkRef In References
' If the reference is broken, send the name to the Immediate Window.
        If chkRef.IsBroken Then
           Debug.Print chkRef.Name
        End If
'copy and repeat the next 2 if statements as needed for additional libraries.
    If InStr(UCase(chkRef.FullPath), UCase("msxml6.dll")) <> 0 Then
                foundXml = True
            End If
    Next

    If (foundXml = False) Then
            'References.AddFromFile ("C:\Windows\System32\msxml6.dll")  <-- For other than XML, modify this line and comment out line below.
            RetVal = AddMsXmlLibrary
            If RetVal = 0 Then MsgBox "Failed to load XML Library (msxml6.dll).  XML upload/download will not work."
    End If

End Sub

添加对库的 XML 引用 由克里斯·阿德纳开发。感谢http://allenbrowne.com/ser-38.html 的洞察力。

Public Function AddMsXmlLibrary(Optional PathFileExtStr As String = "C:\Windows\System32\msxml6.dll") As Integer
On Error GoTo FoundError
AddMsXmlLibrary = 1
References.AddFromFile (PathFileExtStr)

AllDone:
    Exit Function
FoundError:
    On Error Resume Next
    AddMsXmlLibrary = 0
    On Error GoTo 0
End Function

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多