Vb6 获取错误为';未定义用户定义的类型';在代码中
祝你节日快乐 大家好,我是一个使用VB6.0的初学者。我正在使用以下代码并获取“用户定义类型未定义”。代码如下。我获取错误的行突出显示。请提供帮助。我是否应该添加一些引用或组件?如果是,它将是什么。你及时而亲切的帮助将对我更有帮助Vb6 获取错误为';未定义用户定义的类型';在代码中,vb6,Vb6,祝你节日快乐 大家好,我是一个使用VB6.0的初学者。我正在使用以下代码并获取“用户定义类型未定义”。代码如下。我获取错误的行突出显示。请提供帮助。我是否应该添加一些引用或组件?如果是,它将是什么。你及时而亲切的帮助将对我更有帮助 Public Sub LoadDocument() Dim xDoc As MSXML2.DOMDocument Set xDoc = New MSXML2.DOMDocument xDoc.async = False xDoc.
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
它是
MSXML2.IXMLDOMNodeList
,而不是MSXML.IXMLDOMNodeList
,您的参考资料中可能缺少该库。试试这个
手动添加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。如有必要,编辑sub以包含路径
检查库中有无损坏的引用
改编自
就系统基础设施而言,VB6和VB.NET是两种不同的东西。您在这里使用的是哪一个?嗨,steve,我使用的是Visual basic 6.0。他可能还应该添加
选项Explicit
,或者更好地打开IDE选项,以便在创建模块时自动生成它。
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
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