Collection Problem - Possible Bug? 
Author Message
 Collection Problem - Possible Bug?

I am getting some very strange behavior from the
collection object, and am wondering if anyone has a
suggestion.

I have a collection
 Private Const m_Const as String = "NewItem"
 Private Shared m_Coll As New Collection
Added an item
 m_Lookups.Add(New MyObject, m_Const)
At this point, m_Const should be key of a new collection
item, with index of 1.

However, I get an error if I try to access back by key.  
When I break, in the immediate window, these work:
 ? m_Lookups(1)
 ? m_Lookups("NewItem")

But
 ? m_Lookups(m_Const)
does NOT WORK.
The parameter is incorrect.

For a local string variable, the error is
 Run-time exception thrown : System.ArgumentException -
Argument 'Index' is not a valid value.

I've tried next to everything, looked in the helpfile,
tried .ToString, and ctyping as string or object.  It
seems impossible that passing a string object does not
work, while a string does.

Thanks in advance for help!



Tue, 31 Aug 2004 03:27:22 GMT  
 Collection Problem - Possible Bug?
Sorry about the original discrepancy between m_Coll and
m_Lookups in my example, though that is not the cause of
the error.

After some more investigation, it seems that Const is the
problem.  Changing it to a variable instead of a string
constant resolved the issue, much to my dismay.  Does this
seem right, or was there something else going on here?

Thanks!

Alex Pasternak

Quote:
>-----Original Message-----
>I am getting some very strange behavior from the
>collection object, and am wondering if anyone has a
>suggestion.

>I have a collection
> Private Const m_Const as String = "NewItem"
> Private Shared m_Coll As New Collection
>Added an item
> m_Lookups.Add(New MyObject, m_Const)
>At this point, m_Const should be key of a new collection
>item, with index of 1.

>However, I get an error if I try to access back by key.  
>When I break, in the immediate window, these work:
> ? m_Lookups(1)
> ? m_Lookups("NewItem")

>But
> ? m_Lookups(m_Const)
>does NOT WORK.
>The parameter is incorrect.

>For a local string variable, the error is
> Run-time exception thrown : System.ArgumentException -
>Argument 'Index' is not a valid value.

>I've tried next to everything, looked in the helpfile,
>tried .ToString, and ctyping as string or object.  It
>seems impossible that passing a string object does not
>work, while a string does.

>Thanks in advance for help!
>.



Tue, 31 Aug 2004 04:06:11 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Possible Bug, Possible Faulty code

2. Possible bugs/problems in VB User Control

3. Possible latency in Projects Collection?

4. Changing keys in a collection possible?

5. possible to get key from collection?

6. INDEXED COLLECTIONS: Possible?

7. Is it possible to create a VB collection object in an ASP page

8. Pass Data to Collection *is this possible*

9. bug in document pages collection?

10. Bug in Collection class using For Each?

11. Collection content serialization: bug in VB?

 

 
Powered by phpBB® Forum Software