Microsoft KB Archive/193092

= FIX: "Invalid Procedure Call" Error with Preserve Keyword =

Article ID: 193092

Article Last Modified on 3/21/2005

-

APPLIES TO


 * Microsoft Data Access Components Software Development Kit 2.0
 * Microsoft Data Access Components Software Development Kit 2.1
 * Microsoft Visual Basic 6.0 Learning Edition
 * Microsoft Visual Basic 6.0 Professional Edition
 * Microsoft Visual Basic 6.0 Enterprise Edition

-



This article was previously published under Q193092



SYMPTOMS
The following error occurs if a variant set equal to an Array function is redimensioned using the Preserve keyword:

Run-time error '5' "Invalid Procedure Call or Argument"

NOTE: This behavior occurs only under the following two conditions:
 * If Microsoft Data Access Components (MDAC) 2.0 or Visual Studio 6.0 is installed on the computer.

-and-
 * If the array has not been initialized.



CAUSE
This error occurs with the newer version of the OLE automation core file, (version 2.304261). The Oleaut32.dll file is installed in your system directory when you install MDAC 2.0 or Visual Studio 6.0 products.



RESOLUTION
Here are two ways to resolve this problem:

Method One

 * Revert to the older version of Oleaut32.dll (version 2.20.4118). This can be done by re-installing the Windows NT Service Pack 3, which overwrites the newer version of the .dll file. -or -


 * Re-install Visual Basic 5.0, either Service Pack 2 or Service pack 3, which also overwrites the newer version of the .dll file.

NOTE: The preceding workaround can only be used with a Visual Basic 5.0 application running with MDAC 2.0 installed on the computer. The newer version of the automation file, Oleaut32.dll (version 2.304261), must be present on a computer that runs a Visual Basic 6.0 application.

Method Two
You can choose to keep the newer version of the Oleaut32.dll file. However, you cannot preserve your array unless it was initialized prior to the call. For example: Sub Command1_Click Dim VarArr as Variant Dim lngSubScript As Long

VarArr = Array

' Get largest available subscript for the array. lngSubScript = UBound(A)

If (lngSubScript <> -1) Then ' Re-allocate 5 elements of the array and preserve its values. ReDim Preserve VarArr(5) Else ' Re-allocate 5 elements of the array. ReDim VarArr(5) End If     End Sub NOTE: The preceding workaround applies to both Visual Basic 5.0 applications and Visual Basic 6.0 applications running with the newer version of the OLE automation file.



STATUS
Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article.

This bug has been corrected in Microsoft Visual Basic Learning, Professional, and Enterprise Editions for Windows, version 6.0, Service Pack 1.



Steps to Reproduce Behavior
 Start a new project in Visual Basic and choose Standard EXE. Form1 is created by default. Add a CommandButton, named Command1, to Form1.  Paste the following code in the General Declaration section of Form1: Option Explicit Dim VarArr As Variant

Private Sub Command1_Click

' Get the variant to hold an array. VarArr = Array

' Re-allocate 5 elements of the array and preserve its values. ReDim Preserve VarArr(5)        '<--- Error 5 occurs here

End Sub  Run the application or press the F5 key. Click the Command1 button. The "Error 5" occurs.

<div class="references_section">