I had an issue with passing an Array to a Sub By Reference, but the Array actually not get modified. I managed to fix that , but I want to know why.
Here is the example.
Private Function fCountArray(ByRef arrayVar As Variant)
arrayVar(0) = 333
End Function
Sub Test1()
Dim changedArr As Variant
Dim notChangedArr As Variant
' create 2 quick array
changedArr = Array(1, 2, 33, 56, 76, 89, 10)
notChangedArr = Array(1, 2, 33, 56, 76, 89, 10)
'intest = Array(3, 1, 2)
fCountArray (notChangedArr)
Debug.Print notChangedArr(0) 'Print Out 1
fCountArray changedArr
Debug.Print changedArr(0) 'Print Out 333
End Sub
So what is the underlying different between fCountArray (notChangedArr) and fCountArray changedArr
Why fCountArray (notChangedArr) Not pass by reference?