Microsoft KB Archive/159410

= FIX: "Invalid Procedure Call" Referencing Collection Item =

Article ID: 159410

Article Last Modified on 7/15/2004

-

APPLIES TO


 * Microsoft Visual Basic 4.0 Standard Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 Professional Edition
 * Microsoft Visual Basic 4.0 16-bit Enterprise Edition
 * Microsoft Visual Basic 4.0 32-Bit Enterprise Edition

-



This article was previously published under Q159410



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.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Basic 6.0.



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
 Start a new project in Visual Basic. Form1 is created by default. On the Visual Basic menu, click Insert and Class Module to add a new class module.  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

  Change the following properties on the class module: Instancing = 2-Createable MultiUse Public = True

 On the Visual Basic menu, click Insert and Module to add a new Basic code module.  Insert the following code in the code window of the Basic code module: Sub main Load Form1 End Sub

</li> 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</li> Click OK, and then press the F5 key to run the project.</li> Start another session of Visual Basic. A new Project with Form1 appears by default.</li> Place a CommandButton on Form1.</li>  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

</li> On the Visual Basic menu, click Tools and References. Select "OLE Collection Example" on the reference list, and then click OK.</li> Run the project by pressing the F5 key and clicking on Command1. The following error message appears:

"Invalid Procedure Call"

</li></ol>

Additional query words: kbVBp400bug kbVBp600fix kbVBp kbdsd kbDSupport kbVBA

Keywords: kbbug kbfix kbprb KB159410

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.