2012-12-08 103 views
2

当天的问候,错误代码中的'用户定义类型未定义'

嗨,我是一个初学者使用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  
+0

VB6和VB.NET在系统基础设施方面是两回事。你在这里使用哪一个? – Steve

+0

您好史蒂夫,我使用Visual Basic 6.0 – user1724956

回答

2

MSXML2.IXMLDOMNodeList,不MSXML.IXMLDOMNodeList

+2

他也许应该添加'Option Explicit'或更好的,但打开IDE选项以使它在创建模块时自动生成。 – Bob77

0

您的参考文献可能缺失该库。尝试这个。

手动添加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 添加以下子和功能。运行子。如有必要,编辑子包含路径。

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参考克里斯开发Advena酒店库 。感谢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 
相关问题