
using collection of collections
I'd appreciate some recommendations on the best way to approach this
simple(?)
VBA task. I'm new to vba, but familiar with perl, and miss
the easy use of associative arrays.
I want to create a structure like this:
<key1> = item1, item2, ...
<key2> = itema, itemb, ....
I don't know in advance how many keys I need or how many items will be
in each list. The example below doesn't work, but gives an idea of
what i'm thinking of. TopList is a collection of collections. If a new
key is found, then I want to add a new item (a new collection
object)to TopList, and then I want to add items to that sublist. This
is pretty easy to do in Perl, I'm sure there's an easy way to do it in
VB as well... Then I would like to list all the collections and their
contents of TopList
Sub test()
Dim TopList As New Collection
Dim i, j As Integer
For i = 1 To 4
For j = 1 To 3
If TopList.Item(i) Is Nothing Then ' how do i test to see if
the collection exists?
TopList.Add Item:=New Collection, Key:=i
End If
TopList.Item(i).Add j ' is this how i would add an entry to
the sublist?
Next
Next
End Sub