Solved

Declare collection at runtime

Posted on 2002-05-23
8
178 Views
Last Modified: 2010-05-02
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
0
Comment
Question by:bgumble
8 Comments
 
LVL 69

Expert Comment

by:Éric Moreau
ID: 7029336
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.
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 7029427
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(arrayElement)(CollectionElement).Property = "Hello"
0
 

Author Comment

by:bgumble
ID: 7029531
Hi Tim,

Thank you for your suggestion.

Could you please give me and example on how to do this.

Thanks
0
 

Author Comment

by:bgumble
ID: 7029541
Hi Tim,

Thank you for your suggestion.

Could you please give me and example on how to do this.

Thanks
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 
LVL 6

Expert Comment

by:holli
ID: 7029689
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=myCollectionOfCollections.Item("Name").Item("Key") 'v is now "value"


regards, holli
0
 

Author Comment

by:bgumble
ID: 7030881
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("Key") = newvalue

0
 

Author Comment

by:bgumble
ID: 7030918
Actually, what I really need to know is how to add an element to the collection within the collection

thanks..
0
 
LVL 6

Accepted Solution

by:
holli earned 50 total points
ID: 7031444
just as if the collection would be single:

myCollectionOfCollections.Item("Name").Add "Key2", NewValue
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now