Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Listing keys in a collection

Status
Not open for further replies.

venkman

Programmer
Oct 9, 2001
467
US
How do you list the keys in a collection?

For instance:

dim col as new collection
dim v as variant
col.add "item1", "key1"
col.add "item2", "key2"
for each v in col.keys
msgbox "key: " & v
next

would display two message boxes:
"key: key1"
and
"key: key2"


What's the equivalent of col.keys in the code above?

Thanks,
-Venkman
 
I don't think you can do that. The key is used only to refer to a specific item in the collection, you can't actually read it, as far as I can tell.
Rob
[flowerface]
 
Okay, here's the problem I'm running into. I have a bunch of info that I'm storing in a collection of custom objects that are referenced by value (a number), which I'm using as the key. Sometimes, the person(s) using the macro will enter in a duplicate entry. This causes the macro to have an error right now because keys must be unique. Is there a way to trap this error and call a subroutine instead (which will most likely give a dialog box, explaining to a non-technical person what caused the error)?

Thanks,
Venkman
 
never mind, using on error and err.number. Let me know if there's an alternative though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top