?
Solved

Using more than one key in a collection

Posted on 2000-05-04
9
Medium Priority
?
166 Views
Last Modified: 2010-05-02
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
Comment
Question by:adinas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 300 total points
ID: 2777276
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
 

Expert Comment

by:woodsrr
ID: 2777289
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2777321
woodsrr, "This would require two collections..."

What I said... ;-)
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Expert Comment

by:VBGuru
ID: 2777895
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
 
LVL 1

Author Comment

by:adinas
ID: 2785256
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
 
LVL 14

Expert Comment

by:mcrider
ID: 2785269
Thanks for the points...

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

Blame Microsoft ;-)


Cheers!®©
0
 
LVL 1

Author Comment

by:adinas
ID: 2785277
why, do other languages have better "collections"?
0
 
LVL 14

Expert Comment

by:mcrider
ID: 2785296
Better language developers?? ;-)
0
 
LVL 1

Author Comment

by:adinas
ID: 2785368
ha ha

:-)
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question