"Invalid procedure call or argument" 调用一个没有括号的子参数时

"Invalid procedure call or argument" when calling a sub without parenthesing one parameter

我用这段代码写了一个COM-Visible DLL(VB.NET)

' .NET Class with implementing an interface to make it visible
Public Class VisibleClass
    Public Sub callableSub(ByVal names As ACustomCollection, _
                           Optional ByVal doSomething As Boolean = True) _
        Implements IVisibleClass.visibleCallableSub
        Me.doSub(names.process, doSomething)
    End Sub
End Class

' Interface for COM-visibility
<InterfaceType(ComInterfaceType.InterfaceIsDual)> _
Public Interface IVisibleClass
    Sub visibleCallableSub(ByVal names As ACustomCollection, _
                           Optional ByVal doSomething As Boolean = True)
End Interface

这也是创建对象并调用其方法的 ASP 网页:

' stuff.asp
Dim visibleObject
Dim aCustomCollection
Set visibleObject = getNewVisibleInstance (aCollection)
Set aCustomCollection = createEmptyCollection

aCustomCollection.add someStuffs
aCustomCollection.add otherStuffs
aCustomCollection.add lastStuffs

' These calls work:
visibleObject.visibleCallableSub(aCustomCollection)
visibleObject.visibleCallableSub(aCustomCollection), False
visibleObject.visibleCallableSub(aCustomCollection), True
Call document.fetchPropertyCollection ((properties), false)

' These ones don't:
visibleObject.visibleCallableSub someparams
visibleObject.visibleCallableSub someparams, False
visibleObject.visibleCallableSub someparams, True
Call document.fetchPropertyCollection (properties, false)

非工作调用产生以下错误:

Invalid procedure call or argument

我不明白为什么要加括号。我知道这告诉口译员在传递主题之前制作副本,但不知道为什么它是强制性的。

注:与此 是同一个问题,即关于在需要副本的地方传递引用。然而,这个问题被告知是由于 "passing the return value of another function",这使得通过研究更难达到。

如果调用的 Sub/Function 要求一个 value (ByValue),你不能传递引用 ( 'pointer')。在参数周围放置 'make a copy' 括号确保被调用的 Sub/Function 获得 value.

为了明确你的意图,你应该写:

visibleObject.visibleCallableSub (aCustomCollection), False

比照。 , parentheses, adventures.