Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Declare collection at runtime

Posted on 2002-05-23
8
Medium Priority
?
189 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 70

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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

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
 
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 200 total points
ID: 7031444
just as if the collection would be single:

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

704 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