PRB:Parameter Mismatch Error When Pass Properties by ReferenceLast reviewed: June 21, 1995Article ID: Q79597 |
The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for Windows, versions 2.0 and 3.0- Microsoft Visual Basic programming system for Windows, version 1.0
SYMPTOMSWhen trying to pass a control property value by reference to a Sub or Function procedure, you receive a "Parameter Mismatch" error.
CAUSEControl property values in Visual Basic are stored in a formatted form whose location is periodically changed as part of Windows memory management. The values are accessed by handles, not addresses. Although the values behave as their prescribed types when used directly, they cannot be passed by reference to a Sub or Function procedure. Any attempt to do so will generate a "Parameter Mismatch" error. Passing by reference, the default parameter passing method in Visual Basic, places the address of the variable on the stack. The Sub or Function procedure then accesses the address on the stack and uses it to refer to that variable. Sending a control property as a parameter to a Sub or Function procedure will place its handle on the stack instead of an address. Because the handle uses a different form from an address, the Sub or Function procedure finds a value that it is not expecting, and will generate a "Parameter Mismatch" error.
RESOLUTIONPass the property by value instead of by reference. To pass by value, place a set of parentheses around the property variable in the Sub or Function call. This syntax will place the actual value of the property on the stack and tell the Sub or Function procedure to treat it as such. Because an actual memory location is not transferred to the Sub or Function procedure, any changes to the value of the property are localized to that Sub or Function procedure. As an alternative resolution, assign the property value to a temporary variable. The temporary variable has an actual address and can be passed to a Sub or Function procedure in the usual manner. Because an actual address is sent, any change to the temporary variable will be permanent. In order for the actual property variable to reflect this change, you must assign the value of the temporary variable to the property variable upon return from the Sub or Function procedure.
Step-by-Step Example
|
Additional reference words: 1.00 2.00 3.00
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |