Results 1 to 3 of 3

Thread: Collections

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Mar 2000
    Posts
    81

    Cool

    Hi again!
    I've created my own collection object and placed two keyed items in it. As I can iterate over the collection OK, how can I get a list of the keys? I want to say something like

    Code:
    ' in general decls:
    Dim myColl As New Collection
    
    ' in procedure:
    For i = 1 To myColl.Count
         MsgBox "Item " & CStr(i) & " has key " & myColl.Key(i)
    Next
    That can't be impossible can it? Please tell me I don't have to keep track of the keys myself!

    TIA,
    Toot
    Some cause happiness wherever they go; others, whenever they go.

  2. #2
    Addicted Member Dim A's Avatar
    Join Date
    Jul 2000
    Posts
    201
    You shouldn't need the keys...
    You could use the 'for each in collectionName' notation to go through the entire collection or access the individual items by their index.

    I'd say just add a string variable to the class/typeDef that you have a collection of, and assign it the name of the key.

    You could even write an interface class to do it for you...
    And get the functionality of MyColl.key(i) that you want.
    Otherwise, it'd be more like MyColl.Item(i).key
    Assuming that key is a string variable containing the key in your typeDef or has a property get equivalence in your class.

    Gen-X gives a better example here:
    http://forums.vb-world.net/showthrea...threadid=22350

  3. #3
    New Member
    Join Date
    May 2000
    Location
    Saudi Arabia
    Posts
    13

    You cannot get the key value from a Collection but you can get it from a Dictionary.

    You need to add a refrence to "Microsoft Scripting Runtime"

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