简体   繁体   English

“无效的过程调用或参数”调用子时没有括号一个参数

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

I wrote a COM-Visible DLL with this piece of code (VB.NET)我用这段代码(VB.NET)写了一个COM-Visible DLL

' .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

Here is also the ASP web page creating the object and invoking its methods :这里也是创建对象并调用其方法的 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)

Non working calls produce the following error :非工作调用产生以下错误:

Invalid procedure call or argument无效的过程调用或参数

I don't understand why I have to put parenthesis.我不明白为什么我必须加上括号。 I know this tells the interpreter to make a copy before passing theme, but not why it's mandatory.我知道这告诉口译员在传递主题之前制作一个副本,但不知道为什么它是强制性的。

Note : It's the same issue than this one , ie about passing a reference where a copy is required.注:这是比这同一个问题一个,即关于通过在需要复制的参考。 However, the question was told like it's due to "passing the return value of another function", which make it harder to reach through research.然而,这个问题被告知是由于“传递另一个函数的返回值”,这使得通过研究更难达到。

If the called Sub/Function asks for a value (By Value ), you can't pass a reference ('pointer').如果被调用的 Sub/Function 要求一个(按),则不能传递引用(“指针”)。 Putting the 'make a copy ' parentheses around the argument makes sure the called Sub/Function gets a value .在参数周围加上“制作副本”括号可确保被调用的 Sub/Function 获得一个

To make your intention explicit, you should write:为了明确你的意图,你应该写:

visibleObject.visibleCallableSub (aCustomCollection), False

Cf.参见same error , parentheses , adventures .同样的错误括号冒险

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM