-
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
-
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
-
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"