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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you get the Key from a collection Item

Status
Not open for further replies.

SteveMCSE

Programmer
Nov 12, 2002
78
US
Ok, check this out, I put some references to class objects in a collection and use an integer that is converted to a string as the key

MDIParent.AddLoanToCollection clsNewLoan, CStr(intThisForm)

Public Sub AddLoanToCollection(ByRef aLoan As clsLoan, ByVal intFormKey As String)
colLoans.Add aLoan, intFormKey
End Sub

now, how do i extract the key from the collection to use it in a string...

reason:
when i put the class in the collection i send it a number that basically describes which loan it is, such as loan 1 or 2 or 3.
Later, I will use a For...Each loop to go through the collection, but I need the number that was used as a key.
the reason is that a user might delete one or more of the loans from the collection and I don't want it renumbering them. I wan the number that was used as a key to stay that way. So, a count on the for...each loop won't satisfy.
Any ideas? I just don't know what the correct syntax is to get the key back.
thanks. steve.


 
As many amazing things you can do with VB you think they would allow you to make it retrievable! What a rip off. I want my money back! ;) thanks a lot. I did eventually put a data element in the class and just asigned it when the instance is created. Works rather well. Thanks Steve
 
The Collection was a great step forward when it was first introduced. However, over time several drawbacks have reared their ugly head; the inability to retrieve the keys is one, and speed is another.

Although you indicate that you already have a solution, you might find the Dictionary object from the Scripting library useful for future reference
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top