|
-
May 10th, 2009, 06:20 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] A Collection of Collections
I am starting a very data-intensive project that would benefit greatly if I could add the functionality of allowing each item in a specific Collection to be it's own Collection object.
It would also, ideally, need to be infinitely sub-dimensionable as such. For instance (this is only for clarification, it obviously doesn't work like this):
Code:
Dim A As New Collection
Sub Form_Load()
Call NewSubColl(A, "B")
Call NewSubColl(A, "C")
Call NewSubColl(B, "D")
End Sub
Sub NewSubColl(targetColl As Collection, newSubColl)
Dim newSubColl As New collection
targetColl.Add newSubColl
End Sub
(Again, before anyone posts about it, i know this code will not work. I am trying to explain the desired functionality.)
The result would be collections "B" and "C" as two separate items in collection "A", and collection "D" being an item in collection "B".
Anyone able to accomplish this will definitely get reputation from me, and a degree of gratitude that cannot be expressed in words. Without a method of accomplishing this with collections, I will be forced to save all the data in a text file, which would make the processing time ridiculous as I will be reading and storing data constantly.
Thank you so so so much.
-
May 10th, 2009, 07:46 AM
#2
Re: A Collection of Collections
Try this:
Code:
Option Explicit
Dim A As Collection
Sub Form_Load()
InitColls
End Sub
Sub InitColls()
Dim B As Collection
Dim C As Collection
Dim D As Collection
Set A = New Collection
Set B = New Collection
Set C = New Collection
Set D = New Collection
A.Add Item:=B, Key:="B"
A.Add Item:=C, Key:="C"
B.Add Item:=D, Key:="D"
End Sub
Code:
Sub Command1_Click()
Dim n As Long
If A Is Nothing Then InitColls
Debug.Print A.Count
Debug.Print A(1).Count
Debug.Print A(2).Count
Debug.Print A(1)(1).Count
Debug.Print "---------------"
n = A("C").Count + 1
A("C").Add Item:="Item C" & n
n = A("B")("D").Count + 1
A("B")("D").Add Item:="Item D" & n
Debug.Print A.Count
Debug.Print A(1).Count
Debug.Print A(2).Count
Debug.Print A(1)(1).Count
Debug.Print "---------------"
n = A("B")("D").Count
Debug.Print A("B")("D")(n)
n = A("C").Count
Debug.Print A("C")(n)
Debug.Print "---------------"
End Sub
-
May 10th, 2009, 08:22 AM
#3
Thread Starter
Hyperactive Member
Re: A Collection of Collections
Brilliant!
I knew there had to be functionality for it, but I could never figure out the syntax. Thanks tons!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|