• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 176
  • Last Modified:

Using more than one key in a collection

I have a collection but need to get to the correct record by more than one key. For example: I have a collection of users where the key is UserID but I need to also reach a record if I have the UserName. Is there a way without looping throught the whole thing?
0
adinas
Asked:
adinas
1 Solution
 
mcriderCommented:
I think that the only way to do this without looping would be to keep two collections of the same information... One keyed by UserID and the other keyed by UserName...


Cheers!®©
0
 
woodsrrCommented:
You can do a look up collection.  This would require two collections. One main collection with the UserId as the key and a second collection with the UserName as the key.  The second collection has the UserId as it's only value, which you use to look up in the first collection.   Could be done with arrays also.
0
 
mcriderCommented:
woodsrr, "This would require two collections..."

What I said... ;-)
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
VBGuruCommented:
adinas,
I don't agree with you. Even when you specify the key value, the internal implemenation of the collection will/ should have implemented the search algo. So in  your case it is better you implement the search for userId rather than username.
or else you have a funcion which generate a unique key value given a username or userID and use that as the key value. In this case, the function should be able to get the username/id from db you if you spacify anyone.
0
 
adinasAuthor Commented:
Well, using two collections is what I planed to use if there was no solution. I don't understand why collections can't be as versetile as a database table.

Thanks anyways.
0
 
mcriderCommented:
Thanks for the points...

>>I don't understand why collections can't be as versetile as a database table.

Blame Microsoft ;-)


Cheers!®©
0
 
adinasAuthor Commented:
why, do other languages have better "collections"?
0
 
mcriderCommented:
Better language developers?? ;-)
0
 
adinasAuthor Commented:
ha ha

:-)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now