How to Avoid the "ByRef Argument Type Mismatch" ErrorLast reviewed: October 30, 1995Article ID: Q138535 |
The information in this article applies to:
SUMMARYIf you pass a parameter to a function or sub procedure by reference, the type of the actual parameter passed and the corresponding function argument must match. Otherwise, you will get a "ByRef argument type mismatch" error.
MORE INFORMATIONThe reason types have to match with ByRef parameters is that the called procedure is working on the original outside variable through a reference pointer. In the following step-by-step example, if the procedure thinks it is modifying a variant but the outside variable is really a control, the data will probably be ruined. If something is passed by value, Visual Basic can do automatic type conversion. When you pass by value, the inside procedure is working on a copy and can therefore modify it in any way, such as converting the passed object to a temporary Variant and working on that. This applies to simple built-in types as well as objects. Problems like this are easier to understand and debug if you set Option Explicit and declare every variable type explicitly.
Step-by-Step Example
|
Additional reference words: 3.00 4.00 vb4win vb4all
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |