XL97: Compile Error Passing ParamArrayLast reviewed: February 27, 1998Article ID: Q157351 |
The information in this article applies to:
SYMPTOMSIf you are passing a ParamArray to another function, you may receive the following error:
Compile error: Invalid ParamArray use CAUSEYou may receive the aforementioned error message if both of the following are true:
You receive the compile error because Visual Basic for Applications in Microsoft Excel 97 does not allow you to pass a ParamArray to a ByRef argument in another function.
RESOLUTIONMicrosoft provides examples of Visual Basic for Applications procedures for illustration only, without warranty either expressed or implied, including, but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. The Visual Basic procedures in this article are provided 'as is' and Microsoft does not guarantee that they can be used in all situations. While Microsoft support engineers can help explain the functionality of a particular macro, they will not modify these examples to provide added functionality, nor will they help you construct macros to meet your specific needs. If you have limited programming experience, you may want to consult one of the Microsoft Solution Providers. Solution Providers offer a wide range of fee-based services, including creating custom macros. For more information about Microsoft Solution Providers, call Microsoft Customer Information Service at (800) 426-9400. To work around this problem, add "ByVal", without quotation marks, to the argument (receiving the ParamArray) in the function that is being called. For example, the following macro code will return an error when you run the "Test" subroutine:
Sub Test() x = myfun(1) MsgBox x End Sub Function myfun(y As Integer, ParamArray myarr() As Variant) As Integer myfun = otherfun(y, myarr) End Function Function otherfun(y As Integer, myarr As Variant) As Integer otherfun = y * 2 End FunctionIf you change the "otherfun" function declaration to:
Function otherfun(y As Integer, ByVal myarr As Variant) As Integerand run the "Test" subroutine, you will get a message box with a value of 2 displayed.
STATUSMicrosoft has confirmed this to be a problem in the Microsoft products listed at the beginning of this article. We are researching this problem and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATIONWhen you have an argument in the argument list of a function and you do not specify either ByVal (by value) or ByRef (by reference), the argument will be ByRef. This is the default in Visual Basic for all variables.
REFERENCESFor more information about Passing Arguments, click the Index tab in Microsoft Excel 97 Visual Basic for Applications Help, type the following text
passing argumentsand then double-click the selected text to go to the "Passing arguments efficiently" topic.
|
Additional query words: XL97
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |