Solved

Using more than one key in a collection

Posted on 2000-05-04
9
161 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
9 Comments
 
LVL 14

Accepted Solution

by:
mcrider earned 100 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
passing a value with stream reader AFTER a ";" 3 66
Excel VBA, find a string in a column, update a cell 7 74
Problem to With line 4 56
IF ELSE Statement in Excel Macro VBA 16 62
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

815 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now