PRB: "Invalid Procedure Call" Referencing Collection Item

Last reviewed: November 25, 1996
Article ID: Q159410
The information in this article applies to:
  • Standard, Professional, and Enterprise Editions of Microsoft Visual Basic, 16-bit and 32-bit, for Windows, version 4.0

SYMPTOMS

If you reference a collection object created by an out-of-process OLE server with a variable index and the index variable is specified as an Integer or Long in a Dimension statement, the following error appears:

   "Invalid Procedure Call"

RESOLUTION

Make sure that the index variable is specified as Variant in the Dimension statement.

MORE INFORMATION

The out-of-process OLE server (EXE server) that created the collection object receives the index through remote procedure call (RPC). This data is marshaled across the processes and received as a Variant data type only.

This behavior does not occur if the collection object is created in an in-process server because RPC is in the same process and is not needed to transmit the data between the two different processes.

Steps to Reproduce Behavior

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. On the Visual Basic menu, click Insert and Class Module to add a new class module.

  3. Insert the following code into the class module code window:

    Dim x As New Collection

    Public Function PassCollection() As Collection

                x.Add "Item 1"
                x.Add "Item 2"
                x.Add "Item 3"
    
                Set PassCollection = x
       End Function
    
    

  4. Change the following properties on the class module:

    Instancing = 2-Createable MultiUse Public = True

  5. On the Visual Basic menu, click Insert and Module to add a new Basic code module.

  6. Insert the following code in the code window of the Basic code module:

       Sub main()
                Load Form1
       End Sub
    
    

  7. On the Visual Basic menu, click Tools and Options. On the Project tab, change the following fields:

    Startup Form = Sub Main Project Name = OLECOL StartMode = OLE Server Application Description = OLE Collection Example

  8. Click OK, and then press the F5 key to run the project.

  9. Start another session of Visual Basic. A new Project with Form1 appears by default.

  10. Place a CommandButton on Form1.

  11. Insert the following code into the General Declaration section of the

        code window for Form1:
    

        Private Sub Command1_Click()
    
                 Dim c As Collection
                 Dim o As New OLECOL.Class1
                 Dim i As Long
    
                 Set c = o.PassCollection
    
                 For i = 1 To c.Count
        MsgBox c(i)
                 Next i
        End Sub
    
    

  12. On the Visual Basic menu, click Tools and References. Select "OLE

        Collection Example" on the reference list, and then click OK.
    

  13. Run the project by pressing the F5 key and clicking on Command1. The

        following error message appears:
    

        "Invalid Procedure Call"
    


KBCategory: kbole kbprb
KBSubcategory: APrgOther
Additional reference words: 4.00 vb4win vb4all kbstream



THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: November 25, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.