Home > Archive > Visual Basic > March 2004 > Collection with numbers as KEYs
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Collection with numbers as KEYs
|
|
| Abelardo Vacca 2004-03-31, 4:30 pm |
| Hello,
I have a problem accessing a collection by index (position)
The collection item have KEYs that correspond to numbers. When I try to access the collection by Index, VB assumes I'm trying to access by KEY and I can't get the desired result.
For instance , myCollection has 3 items with keys "1", "5", "6"
When I try:
myCollection.Item(3) ... i get Nothing
I tried also:
myCollection.Item(CLng(3))
and
dim l as long
l = 3
myCollection.Item(l)
None of them work, is this normal?
Thanks,
Abelardo
| |
| Abelardo Vacca 2004-03-31, 11:30 pm |
| Well, I got a hold of the person who coded the object.
He was just masking a Private Collection by creating a public "Item" function. The problem is his function is delcared as
Public Function Item(k as string) as object
Item = myPrivateColleciton.Item(k)
End function
(the fucntion is accutally a bit longer as it has error checking for existing items)
Which will normally transform k into a string ALWAYS.
I cannot understand why they did that. I would assume a Variant would keep all functionalities of a Collection, right?
ie
Public function Item(k as variant) as object
Item = myPrivateCollection.Item(k)
End Function
Wouldn't you agree?
Thanks,
Abelardo (... Trying to keep his with fellow office workers)
|
|
|
|
|