-1

I wrote a COM-Visible DLL with this piece of code (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

Here is also the ASP web page creating the object and invoking its methods :

' 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, i.e. 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.

Amessihel
  • 5,891
  • 3
  • 16
  • 40
  • 2
    Possible duplicate of ["Invalid procedure call" error when passing a variable as argument vs. passing the return value of another function](https://stackoverflow.com/questions/31747341/invalid-procedure-call-error-when-passing-a-variable-as-argument-vs-passing-t) – user692942 Oct 18 '17 at 09:26
  • @Lankymart It's the same issue - passing a reference where a copy is required. However, the question mentions "vs. passing the return value of another function" which could be misleading... So I don't know what to do... – Amessihel Oct 19 '17 at 09:35
  • Also don't take downvotes personally, they're not a personal attack towards you or anyone – LW001 Oct 19 '17 at 10:13

1 Answers1

0

If the called Sub/Function asks for a value (ByValue), you can't pass a reference ('pointer'). Putting the 'make a copy' parentheses around the argument makes sure the called Sub/Function gets a value.

To make your intention explicit, you should write:

visibleObject.visibleCallableSub (aCustomCollection), False

Cf. same error, parentheses, adventures.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • I updated by adding two lines with a `Call`... A `Call` forces a copy, right ? If so, why do I need to put parenthesis even in this case ? – Amessihel Oct 17 '17 at 11:55
  • The (silly) Call keyword just allows you to use parameter list parentheses; it does **not** copy. Follow the second link to read about different kind of () and their function. – Ekkehard.Horner Oct 17 '17 at 11:58
  • *“(silly) Call keyword”* - Why is it silly? The `Call` statement is very useful, it makes identifying procedures in code a breeze and allows `Sub` procedures to be called using parentheses. Used it for years and never had a problem, the only reason it would be silly is if the tendency is to write sloppy code that is only comprehensible to you. Each to their own I guess. – user692942 Oct 18 '17 at 20:50