Article ID: 138519
Article Last Modified on 12/9/2003
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.
Private Sub Command1_Click()
y = Test(inc(1), inc(2), inc(3))
Debug.Print y
End Sub
Function Test(ParamArray z()) As Integer
Test = z(2)
End Function
Public Function inc(y As Integer) As Integer
Static x As Integer
x = x + 1
inc = x + y
End Function
Function Test(z0, z1, z2) As Integer
Test = z2
End Function
In this case, the debug window prints out 6.
Private Sub Command1_Click()
X1 = inc(1)
X2 = inc(2)
x3 = inc(3)
y = Test(X1, X2, X3)
Debug.Print y
End Sub
Private Sub Command1_Click()
Test
End Sub
Public Function inc(x As Integer, ByVal y As Integer) As Integer
x = x + 1
inc = x
Debug.Print "x: "; x; "evaluated at position"; y
End Function
Public Sub Test()
Dim x As Integer
x = -1
y = Switch(False, inc(x, 1), False, inc(x, 2), True, inc(x, 3))
Debug.Print y
End Sub
Keywords: kbprogramming kbprb KB138519