PRB: Arguments Are Evaluated from Right to Left in Some CasesLast reviewed: September 29, 1997Article ID: Q138519 |
The information in this article applies to:
SYMPTOMSVisual Basic 4.0 allows you to pass a variable number of arguments to a subroutine or function by using a parameter array (ParamArray). Although, arguments passed to another function or subroutine are evaluated from right to left when a parameter array is used in the 32-bit version, the 16-bit version evaluates arguments from left to right when a parameter array is used. Arguments are evaluated from left to right if a set number of arguments is passed to a function or subroutine in both the 16-bit and 32-bit versions. Arguments are evaluated from right to left when using the switch function in both the 16-bit and 32-bit versions of Visual Basic.
WORKAROUNDCode that relies on the order of evaluation of arguments passed to another function is dangerous code in any language. To correct code that fails because of the order of evaluation, Microsoft recommends that arguments be explicitly calculated before being passed to a function or subroutine.
STATUSThis behavior is by design.
MORE INFORMATIONThe following table summarizes the order in which arguments are evaluated:
Version Parameter Array Set Number of Arguments Switch Function 16-bit Left to Right Left to Right Right to Left 32-bit Right to Left Left to Right Right to LeftThe following example illustrates the danger of relying on the order of evaluation of arguments. In all cases, you can fix the code by first calculating the arguments and then passing the results to the function.
Steps to Reproduce Behavior When Using a ParamArray ArgumentThis example was constructed in Visual Basic 4.0 using the 32-bit version, but the 16-bit or 32-bit version can be used.
Steps to Reproduce Behavior When Using the Switch Function
Keywords : PrgOther VB4ALL VB4WIN vbwin GnrlVb kbprg Technology : kbvba Version : WINDOWS:4.0 Platform : NT WINDOWS Issue type : kbprb |
================================================================================
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |