Storing a collection in a collection 
Author Message
 Storing a collection in a collection

Hello,
I need help with the proper syntax in building a collection and then
populating another collection with the contents of the first
collection. I will need to be able to select a specific item in both
collections. For example in VB6 I would add key/value pairs to the
InnerCollection and then add that collection to the OuterCollection
with key/object. To retrieve items from the InnerCollection I would do
OuterCollection.Item(3).Item("ItemIWant"). I have tried several things
but can not get anthing to work properly. Not sure which collection
type to use in .net. I believe I have the InnerCollection working
correctly correct. Please provide examples. I would like to be able to
have Option Strict On. My goal is to be able to pass the
OuterCollection between my data layer and business layer. I want to
use pure .net and not use the compatability layer.
Thank you for your time.
Dan Conant


Sat, 17 Sep 2005 03:07:24 GMT  
 Storing a collection in a collection
Hi Dan,

The following code creates an inner collection with 3 indexed strings, and
then adds this collection to the outer collection:

Option Strict On
Option Explicit On

Module Module1
    Dim InnerColl As New Microsoft.VisualBasic.Collection
    Dim OuterColl As New Microsoft.VisualBasic.Collection

    Sub Main()
        InnerColl.Add("The Inner Item1", "InnerItem1")
        InnerColl.Add("The Inner Item2", "InnerItem2")
        InnerColl.Add("The Inner Item3", "InnerItem3")

        OuterColl.Add(InnerColl)

        MsgBox(CType(OuterColl.Item(1),
Microsoft.VisualBasic.Collection).Item("InnerItem3"))
    End Sub

End Module

Hope this helps,
--
Abel, VB Team
This posting is provided "AS IS" with no warranties, and confers no rights.



Sat, 17 Sep 2005 04:57:39 GMT  
 Storing a collection in a collection

Quote:
> Hi Dan,

> The following code creates an inner collection with 3 indexed strings, and
> then adds this collection to the outer collection:

> Option Strict On
> Option Explicit On

> Module Module1
>     Dim InnerColl As New Microsoft.VisualBasic.Collection
>     Dim OuterColl As New Microsoft.VisualBasic.Collection

>     Sub Main()
>         InnerColl.Add("The Inner Item1", "InnerItem1")
>         InnerColl.Add("The Inner Item2", "InnerItem2")
>         InnerColl.Add("The Inner Item3", "InnerItem3")

>         OuterColl.Add(InnerColl)

>         MsgBox(CType(OuterColl.Item(1),
> Microsoft.VisualBasic.Collection).Item("InnerItem3"))
>     End Sub

> End Module

> Hope this helps,

Hello Abel,

Thank you for your reply. I already new how to do what you show. I
wanted to use the new dotnet syntax because sooner or later the
"VisualBasic" layer will go way. Can you suggest a way to this via one
of the dotnet collections?

Thank You,
Dan Conant



Sat, 17 Sep 2005 20:28:04 GMT  
 Storing a collection in a collection
Hi Dan,

The Microsoft.VisualBasic.Collection class is part of the .Net Framework so
it won't go away. If you still want to use the other collections in the
System.Collections Namespace, your best bet is to derive your own class
from System.Collections.Specialized.NameObjectCollectionBase. Note that you
will need to implement and expose the Add, Item and Remove methods and have
them call into the protected base methods that provide that functionality.

HTH,      

Abel, VB Team
This posting is provided "AS IS" with no warranties, and confers no rights.



Sun, 18 Sep 2005 04:44:43 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Collections, Collections and More Collections

2. Document collections and AllForms collections

3. Creating a CDO collection from an Outlook collection

4. using collection of collections

5. collection in collection

6. Migrating to System.Collections.IEnumerator from VB6.Collection

7. Persisting a Collection of a Collection

8. Collection of Collections?

9. Collections, swapping items in a collection

10. Collections of Collections..how?

11. collections of collections

12. Collection of Collections

 

 
Powered by phpBB® Forum Software