S
StevenM
As a habit, I normally pass variables to functions "ByVal." But I was
wondering if it was faster/better to pass an array "ByRef" even if one wasn't
planning to modify its contents? Doesn't "ByVal" create a new array of the
same size?
Also, it appeared to me that to pass an array, one has to use a Variant
variable, is that correct?
The following code seemed to work as expected.
Sub ArrayTest()
Dim arrayX(4 To 99) As Byte
arrayX(4) = 11
arrayX(5) = 99
Call PassArray(arrayX, arrayX)
MsgBox arrayX(4)
MsgBox arrayX(5)
End Sub
Function PassArray(ByVal arrayY As Variant, ByRef arrayZ As Variant)
MsgBox "The Bounds of this array is: " & LBound(arrayY) & " and " &
UBound(arrayY)
MsgBox arrayY(4)
arrayY(4) = 66
arrayZ(5) = 88
End Function
Steven Craig Miller
wondering if it was faster/better to pass an array "ByRef" even if one wasn't
planning to modify its contents? Doesn't "ByVal" create a new array of the
same size?
Also, it appeared to me that to pass an array, one has to use a Variant
variable, is that correct?
The following code seemed to work as expected.
Sub ArrayTest()
Dim arrayX(4 To 99) As Byte
arrayX(4) = 11
arrayX(5) = 99
Call PassArray(arrayX, arrayX)
MsgBox arrayX(4)
MsgBox arrayX(5)
End Sub
Function PassArray(ByVal arrayY As Variant, ByRef arrayZ As Variant)
MsgBox "The Bounds of this array is: " & LBound(arrayY) & " and " &
UBound(arrayY)
MsgBox arrayY(4)
arrayY(4) = 66
arrayZ(5) = 88
End Function
Steven Craig Miller