Results 1 to 6 of 6

Thread: Is there a way to create a collection of collections?

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    513

    Is there a way to create a collection of collections?

    Is there a way to create a collection of collections?

    e.g. I created a collection ListOf(Lines)
    After I add all my lines to it, I want to store this colleciton in another listOf(Collections). The reason I want to do this is because i want to create several separate collections of lines and I'll need to loop through them all to look for a certain line and I thought this would be a good approach if it's possible.

    i tried to create a listOf(Collection) but when i try to add my listOf(Lines) to it, it complains because the list is a colleciton of lines.

    thanks,
    Proctor

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Is there a way to create a collection of collections?

    List(Of List(Of Lines))

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Mar 2008
    Posts
    513

    Re: Is there a way to create a collection of collections?

    A list of a list ....that's brilliant!!! I gave it a try and it works great!

    thank you for your help!!

    may i ask another quick question?
    i want to build my collections of lines on the fly. e.g. the first i will be called colList1 and will be hard-coded like this:
    dim colList1 as new listOf(lines)

    then, when i need to start a new list of lines i wanted to do something like this in my code:

    dim colList & "2" as new listOf(lines)

    i haven't had any luck with this. do you also know if this is possible?

    thanks again for showing me how to do a list of a list.....
    Proctor

  4. #4
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Is there a way to create a collection of collections?

    nope... you can't do it like that... once you put your list in a list, you can assign a new list to your same variable... just make sure it is a a NEW list.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  5. #5
    Fanatic Member
    Join Date
    Aug 2006
    Location
    In my head
    Posts
    913

    Re: Is there a way to create a collection of collections?

    If you are adding a new list of lines to your collection then you would do this:
    Code:
    lst.Add(New List(of Lines))
    There is no naming of items within your collection. You would have to use the Find function to find a match to whatever you are searching for or use iteration to go through each element and/or subelement (since your nesting collections).

    Edit: unless you have a custom class that has a name property, then you can put your text, concatenated and all as its name!

    If you are looking to declare a variable on the fly for use in code, I do not think that is not gonna happen. You cannot concatenate strings to create a variable name either. (ie Dim str & i as String where i is part of a For loop) You can however create controls or classes using the CType and/or DirectCast functions on the fly and name them as you please.

    Hope that helps a little bit....

    D
    Platforms of choice: Visual Studio 2005/2008 Professional : Visual Studio 2010 Enterprise : PHP - Notepad++/WAMP

    Please Rate If I helped you.
    Please remember to mark threads as closed if your issue has been resolved.

    Reserved Words in Access | Connection Strings

  6. #6
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Is there a way to create a collection of collections?

    Quote Originally Posted by dminder View Post
    If you are adding a new list of lines to your collection then you would do this:
    Code:
    lst.Add(New List(of Lines))
    There is no naming of items within your collection. You would have to use the Find function to find a match to whatever you are searching for or use iteration to go through each element and/or subelement (since your nesting collections).

    Edit: unless you have a custom class that has a name property, then you can put your text, concatenated and all as its name!

    If you are looking to declare a variable on the fly for use in code, I do not think that is not gonna happen. You cannot concatenate strings to create a variable name either. (ie Dim str & i as String where i is part of a For loop) You can however create controls or classes using the CType and/or DirectCast functions on the fly and name them as you please.

    Hope that helps a little bit....

    D
    There's also the Dictionary(Of String, List(Of Lines)) .... then you can give any string name as the key to each of your lists...

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width