PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Dynamically creating and naming collections
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
Dynamically creating and naming collections
![]() |
Dynamically creating and naming collections |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
Hey,
Does anyone know how to create and name collections dynamically? I am writing some vb.net (VB2005) code which requires me to create an unknown number of collections and then add them to a master collection so I can operate on them in a loop. Thanks, Paul. |
|
|
|
#2 |
|
Guest
Posts: n/a
|
On Mar 14, 6:46 am, "paulb" <paulberming...@gmail.com> wrote:
> Hey, > > Does anyone know how to create and name collections dynamically? I am > writing some vb.net (VB2005) code which requires me to create an > unknown number > of collections and then add them to a master collection so I can > operate on them in a loop. > > Thanks, > > Paul. Right off hand, it sounds like you want an XML DOM. But without more information, it's hard to say. What, exactly, are you trying to do? Can you provide a little more information? |
|
|
|
#3 |
|
Guest
Posts: n/a
|
On Mar 14, 5:46 am, "paulb" <paulberming...@gmail.com> wrote:
> Hey, > > Does anyone know how to create and name collections dynamically? I am > writing some vb.net (VB2005) code which requires me to create an > unknown number > of collections and then add them to a master collection so I can > operate on them in a loop. > > Thanks, > > Paul. Paul, What about using a Dictionary to store each individual collection? The key in the Dictionary would be the name and the value would be the actual collection. Brian |
|
|
|
#4 |
|
Guest
Posts: n/a
|
On Mar 14, 2:51 pm, "Brian Gideon" <briangid...@yahoo.com> wrote:
> On Mar 14, 5:46 am, "paulb" <paulberming...@gmail.com> wrote: > > > Hey, > > > Does anyone know how to create and name collections dynamically? I am > > writing some vb.net (VB2005) code which requires me to create an > > unknown number > > of collections and then add them to a master collection so I can > > operate on them in a loop. > > > Thanks, > > > Paul. > > Paul, > > What about using a Dictionary to store each individual collection? > The key in the Dictionary would be the name and the value would be the > actual collection. > > Brian How do I create a new collection in the code? The answer is probably simple. Currently I am using: Private Sub Form_Load Dim Collection1 As Collection Collection1 = New Collection Collection1.Add (Class1, Key1) End SubI would like to be able to create new collections when an event is triggered. Is there some kind of CreateCollection method I can use? |
|
|
|
#5 |
|
Guest
Posts: n/a
|
On Mar 14, 9:25 am, "paulb" <paulberming...@gmail.com> wrote:
> On Mar 14, 2:51 pm, "Brian Gideon" <briangid...@yahoo.com> wrote: > > > > > > > On Mar 14, 5:46 am, "paulb" <paulberming...@gmail.com> wrote: > > > > Hey, > > > > Does anyone know how to create and name collections dynamically? I am > > > writing some vb.net (VB2005) code which requires me to create an > > > unknown number > > > of collections and then add them to a master collection so I can > > > operate on them in a loop. > > > > Thanks, > > > > Paul. > > > Paul, > > > What about using a Dictionary to store each individual collection? > > The key in the Dictionary would be the name and the value would be the > > actual collection. > > > Brian > > How do I create a new collection in the code? The answer is probably > simple. > > Currently I am using: > > Private Sub Form_Load > Dim Collection1 As Collection > > Collection1 = New Collection > > Collection1.Add (Class1, Key1) > > End SubI would like to be able to create new collections when an event > is triggered. Is there some kind of CreateCollection method I can use?- Hi, The following example creates 10 new List collections and adds them to a Dictionary. The List collections are keyed by a String representation of the numbers 1 through 10. Private m_Dictionary as New Dictionary(Of String, List(Of SomeObject)) Public Sub Foo() For i as Integer = 0 To 10 m_Dictionary.Add(i.ToString(), New List(Of SomeObject)) Next End Sub Brian |
|
|
|
#6 |
|
Guest
Posts: n/a
|
On Mar 14, 3:42 pm, "Brian Gideon" <briangid...@yahoo.com> wrote:
> On Mar 14, 9:25 am, "paulb" <paulberming...@gmail.com> wrote: > > > > > On Mar 14, 2:51 pm, "Brian Gideon" <briangid...@yahoo.com> wrote: > > > > On Mar 14, 5:46 am, "paulb" <paulberming...@gmail.com> wrote: > > > > > Hey, > > > > > Does anyone know how to create and name collections dynamically? I am > > > > writing some vb.net (VB2005) code which requires me to create an > > > > unknown number > > > > of collections and then add them to a master collection so I can > > > > operate on them in a loop. > > > > > Thanks, > > > > > Paul. > > > > Paul, > > > > What about using a Dictionary to store each individual collection? > > > The key in the Dictionary would be the name and the value would be the > > > actual collection. > > > > Brian > > > How do I create a new collection in the code? The answer is probably > > simple. > > > Currently I am using: > > > Private Sub Form_Load > > Dim Collection1 As Collection > > > Collection1 = New Collection > > > Collection1.Add (Class1, Key1) > > > End SubI would like to be able to create new collections when an event > > is triggered. Is there some kind of CreateCollection method I can use?- > > Hi, > > The following example creates 10 new List collections and adds them to > a Dictionary. The List collections are keyed by a String > representation of the numbers 1 through 10. > > Private m_Dictionary as New Dictionary(Of String, List(Of SomeObject)) > > Public Sub Foo() > > For i as Integer = 0 To 10 > m_Dictionary.Add(i.ToString(), New List(Of SomeObject)) > Next > > End Sub > > Brian This is what I was looking for. Thanks, Paul. |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

