Populating collection with arrays

前端 未结 5 1154
忘掉有多难
忘掉有多难 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:47

    If you want the collection to have a copy of the array, and not a reference to the array, then use the array.clone method:-

    Dim myCollection As New Collection
    Dim myDates() as Date
    Dim i As Integer
    
    Do
       i = 0
       Array.Resize(myDates, 0)
       Do
           Array.Resize(myDates, i + 1)
           myDates(i) = Now
           ...
           i += 1
       Loop
       myCollection.Add(myDates.Clone)
    Loop
    

    At the end, myCollection will contain the accumulative collection of myDates().

提交回复
热议问题