3

我正在尝试从我的代码中返回一个值。只显示代码要容易得多:

Function writeHeaderData() As IXMLDOMNode

    Dim xmlDoc As New MSXML2.DOMDocument30
    xmlDoc.async = False
    xmlDoc.LoadXML "<Foo></Foo>"
    Dim Foo As IXMLDOMNode
    Set Foo = xmlDoc.DocumentElement

    'code snip; includes appending lots of things to Foo

    'the error is on this line:
    writeHeaderData = Foo
    Exit Function

End Function

我已经用谷歌搜索了,但没有用。这个函数是从主子例程调用的,我试图将返回的 IXMLDOMNode 附加到一个更大的函数,但我一直收到一个"Object variable or With block variable not set“错误” writeHeaderData = Foo。这是怎么回事?

4

1 回答 1

7

在VB(A)中,当你想给一个对象变量赋值时,包括给一个函数的返回值赋值,你需要使用Set,所以:

'the error is on this line:
writeHeaderData = Foo

应该

Set writeHeaderData = Foo
于 2012-05-14T16:05:20.663 回答