The following code:
Dim arr As Variant, item As Variant
arr = Array(1)
arr(0) = 5
For Each item In arr
Debug.Print item
Next
prints 5; it seems to successfully modify the contents of the array.
However, if I create a Dictionary, and place an array at one of the dictionary keys:
Dim dict As New Scripting.Dictionary, item As Variant
dict("a") = Array(1)
dict("a")(0) = 5
For Each item In dict("a")
Debug.Print item
Next
the array is read-only; the edit is ignored, and the code prints 1 -- the original value.
Why can I modify the elements of an array referenced through a variable, but not those of an array referenced through a call to Dictionary.Item; and how can I resolve this?
Dim arrarr = dict("a"): arr(0) = 5For Each item In arrarr = dict("a")isn't array via dictionary?