I'm new to VBA, and I can't seem to work out a very simple concept - assigning one array to another, both being of equal size and type. Like in this example:
Option Explicit
Sub main()
Dim arr1(2), arr2(2) As Double
arr1(0) = 5
arr1(1) = 10
arr2 = arr1 'error here
Debug.Print arr2(0)
Debug.Print arr2(0)
End Sub
Running this returns an error
"Can't assign to array"
Now, I know I can iterate through every element with a For loop, but in some advanced cases, it is impractical to use - for example, I have a slow-loading function that returns an array, and because of that, I'd like to run it only once, taking it's whole return value and assigning to some other array, like this:
arr1 = Very_Slow_Function_That_Returns_An_Array()
But obviously, this won't work either, and will produce the same error. So, what can be done? Can someone give some advice on how to assign a whole array to another array without having to iterate through every element?
arr1as aVariantandarr2as aDouble- That's a problem.