bgumble
asked on
Declare collection at runtime
Hi I am new to Visual Basic.
I can declare a collection in Visual Basic by
Dim mybooks As New Collection
however at run time I would like to create new collections
which a user may type in.
so I woudl like to
dim ("whatever usertypes in") as new collection
and use
"whatever usertypes in" as a normal object name.
Thanks for any help.
Ber
I can declare a collection in Visual Basic by
Dim mybooks As New Collection
however at run time I would like to create new collections
which a user may type in.
so I woudl like to
dim ("whatever usertypes in") as new collection
and use
"whatever usertypes in" as a normal object name.
Thanks for any help.
Ber
Collections are compiled so you can create them at run-time. If you are using collections to store regular data (integer, date, string, ...), you can use disconnected ADO Recordset instead of collection. Recordsets can exists without a database and you can add them at run-time.
There is no way that you are going to get something like this. You could create an array of collections so that you could reference an element in a collection using something like:
aryCollections(arrayElemen t)(Collect ionElement ).Property = "Hello"
aryCollections(arrayElemen
ASKER
Hi Tim,
Thank you for your suggestion.
Could you please give me and example on how to do this.
Thanks
Thank you for your suggestion.
Could you please give me and example on how to do this.
Thanks
ASKER
Hi Tim,
Thank you for your suggestion.
Could you please give me and example on how to do this.
Thanks
Thank you for your suggestion.
Could you please give me and example on how to do this.
Thanks
Since a collection can hold all types, it can also handle other collections, so:
'A collection to hold the collections
dim myCollectionOfCollections as new collection
'The member to add
dim myCollectionMember as Collection
....
'Adding a collection
s="Name"
set myCollectionMember = new collection
myCollectionMember.add "Value", "Key"
myCollectionOfCollections. add myCollectionMember,s
'Dereferencing a collection
v=myCollectionOfCollection s.Item("Na me").Item( "Key") 'v is now "value"
regards, holli
'A collection to hold the collections
dim myCollectionOfCollections as new collection
'The member to add
dim myCollectionMember as Collection
....
'Adding a collection
s="Name"
set myCollectionMember = new collection
myCollectionMember.add "Value", "Key"
myCollectionOfCollections.
'Dereferencing a collection
v=myCollectionOfCollection
regards, holli
ASKER
Hi Holli
Thanks for the help..
That all works
however I can't seem to easly add an item to the collection that is within the collection..
I've tried
myCollectionOfCollections. Item("Name ").Item("K ey") = newvalue
Thanks for the help..
That all works
however I can't seem to easly add an item to the collection that is within the collection..
I've tried
myCollectionOfCollections.
ASKER
Actually, what I really need to know is how to add an element to the collection within the collection
thanks..
thanks..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.