Results 1 to 4 of 4

Thread: [RESOLVED] Easy - Loop through collection of collections

  1. #1

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Resolved [RESOLVED] Easy - Loop through collection of collections

    I have a Collection, the keys are strings and the values are Collections. In the sub Collections the keys are strings and values are Singles/Floats.

    How would I loop through all of the data? I need to get the keys and values not just the values.

    I've tried this but it produces a cast error:

    Code:
            Dim de As DictionaryEntry
    
            For Each de In MyCol
                'key should be in de.Key
                'value should be in de.Value
            Next
    Cheers
    Chris

  2. #2
    PowerPoster motil's Avatar
    Join Date
    Apr 2009
    Location
    Tel Aviv, Israel
    Posts
    2,143

    Re: Easy - Loop through collection of collections

    try this maybe:

    Code:
      Dim de As DictionaryEntry
            de.Key = "Test"
            de.Value = "1232"
    
            For Each MyCol In de.Value
                MsgBox(de.Value & " " & de.Key)
    
    
                'key should be in de.Key
                'value should be in de.Value
            Next
    * Rate It If you Like it

    __________________________________________________________________________________________

    "Programming is like sex: one mistake and you’re providing support for a lifetime."

    Get last SQL insert ID

  3. #3

    Thread Starter
    Frenzied Member the182guy's Avatar
    Join Date
    Nov 2005
    Location
    Cheshire, UK
    Posts
    1,473

    Re: Easy - Loop through collection of collections

    Nevemind, solved it by using Hashtables instead of collections
    Chris

  4. #4
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: [RESOLVED] Easy - Loop through collection of collections

    Using a different method doesn't necessarily answer the question, however...

    If it's a Dictionary, you can use a KeyValuePair Structure, Or you can loop through the keys and values (the values in this case are simply objects, but you can make them whatever you like):

    Code:
    		Dim MyDictionary As Dictionary(Of String, Object)
    
    		For Each kvp As KeyValuePair(Of String, Object) In MyDictionary
    		Next
    
    		For Each key As String In MyDictionary.Keys
    		Next
    
    		For Each value As Object In MyDictionary.Values
    		Next
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

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