Populating collection with arrays

前端 未结 5 1150
忘掉有多难
忘掉有多难 2021-01-11 12:03
Dim A As Collection
Set A = New Collection

Dim Arr2(15, 5)
Arr2(1,1) = 0
\' ...

A.Add (Arr2)

How can I access the Arr2 through

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-11 12:39

    @jtolle is correct. If you run the code below and inspect the values (Quick Watch is Shift-F9) of Arr2 and x you will see that they are different:

    Dim A As Collection
    Set A = New Collection
    Dim Arr2(15, 5)
    
    Arr2(1, 1) = 99
    
    ' ...
    
    A.Add (Arr2) ' adds a copy of Arr2 to teh collection
    
    Arr2(1, 1) = 11  ' this alters the value in Arr2, but not the copy in the collection
    
    Dim x As Variant
    
    x = A.Item(1)
    x(1, 1) = 15  ' this does not alter Arr2
    

提交回复
热议问题