The information in this article applies to:
SYMPTOMS
When trying to use the Set keyword to assign a value to a formal parameter
passed to a Visual Basic Sub or Function procedure, you may get a "Can't
Set formal parameter" error at compile or run time. CAUSE
This behavior is by design. You cannot use a procedure's formal parameter
as the destination of a Set statement. WORKAROUNDYou can use a Set statement on an array of objects that is passed as a parameter. For example, you can modify the code shown in the "Steps to Reproduce Behavior" section to the following to prevent the error:
RESOLUTIONIf you make the object variable Global instead of passing it as a parameter, you can use Set statements inside procedures. STATUSThis behavior is by design. MORE INFORMATIONObjects as parameters can be thought of as a copy of the structure that defines the object. If Set statements were allowed on these objects, this would change the value inside the routine, but upon returning from the routine the changes would be lost and the object variable would revert back to its original value. Steps to Reproduce Behavior
More Steps to Reproduce BehaviorHere is another set of steps that result in the error:
ByVal is allowed with the variable types listed in the error message, but it is not allowed with any other variable type. Additional query words: 2.00 3.00
Keywords : kbcode PrgOther |
Last Reviewed: August 18, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |