Case 1: (execution time 2 seconds)
Dim mcol As New Collection
Dim k As Collection
For lCount = 1 To 120000
Set k = New Collection
mcol.Add k
Next
lCount = mcol.Count
For lIndex = 1 To lCount
mcol.Remove 1
Next lIndex
Set mcol = Nothing
Case 2: (execution time 30 seconds)
Dim mcol As New Collection
Dim k As Collection
For lCount = 1 To 120000
Set k = New Collection
mcol.Add k
Next
lCount = mcol.Count
For lIndex = lCount To 1 Step -1
mcol.Remove lIndex
Next lIndex
Set mcol = Nothing
Thanks
Accessing a collection by index number is supported, but not very well
optimized. If you are using an index, then an array may be better for the
task.
FYI: Try that same test using a key value:
> mcol.Add k "k" & Cstr(lcount)
... then ...
> mcol.Remove "k" & Cstr(lIndex)
Do you notice a difference? What does that tell you about indexing and
keys when using a collection?
LFS