Collection.Add and Collection.Item question? 
Author Message
 Collection.Add and Collection.Item question?

I've got this simple code:

Private Sub Command1_Click()
    Dim strings As New Collection

    strings.Add "?", "?"
    MsgBox strings("ae")
End Sub

Incredibly the MsgBox strings("ae") statement actually displays an "?"
letter. I'm not able to do:
Private Sub Command1_Click()
    Dim strings As New Collection

    strings.Add "?", "?"
    strings.Add "ae", "ae"
End Sub

This code fails as there's already an element with the key "ae". It must
mean, that "?" is converted to "ae". Probably somebody think this is smart.
From my point of view, it's obvious that no conversion of the key argument
to the various collection methods is tolerable at all.

Do any of you know if I may do something to be able to add both an "?" and
"ae" to the same collection?

Best regards,

Henrik



Tue, 09 Dec 2003 06:10:33 GMT  
 Collection.Add and Collection.Item question?
Strange... maybe you stubbled onto a bug.. report it and see what happens..

For a work around, I got this to work..
'==============
   Dim strings As New Collection
   Dim s As String

   s = "?"
   strings.Add s, s & Len(s)
   s = "ae"
   strings.Add s, s & Len(s)
   MsgBox strings("ae2")

   s = "?"
   MsgBox strings(s & Len(s))

   s = "ae"
   MsgBox strings(s & Len(s))
'==============

a bit more work than it should be but... at least, you're not stuck dead in
your tracks..


Quote:
> I've got this simple code:

> Private Sub Command1_Click()
>     Dim strings As New Collection

>     strings.Add "?", "?"
>     MsgBox strings("ae")
> End Sub

> Incredibly the MsgBox strings("ae") statement actually displays an "?"
> letter. I'm not able to do:
> Private Sub Command1_Click()
>     Dim strings As New Collection

>     strings.Add "?", "?"
>     strings.Add "ae", "ae"
> End Sub

> This code fails as there's already an element with the key "ae". It must
> mean, that "?" is converted to "ae". Probably somebody think this is
smart.
> From my point of view, it's obvious that no conversion of the key argument
> to the various collection methods is tolerable at all.

> Do any of you know if I may do something to be able to add both an "?" and
> "ae" to the same collection?

> Best regards,

> Henrik



Tue, 09 Dec 2003 06:41:25 GMT  
 Collection.Add and Collection.Item question?
I can reproduce your results here so this is a 'situation' with the collection object.

I did check the ansi value that VB is using for ? and it is indeed 230.

I do not see any way to examine the keys in a collection once they have been created so I couldn't verify that the collection object
was converting the ? to ae but it sure looks like it is.

The same results do not occur with ? and ce or ? and CE but they do occur with ce and CE so the collection object is not
case-sensitive! To bad in mho since this greatly reduces the possible keys.

One thing, if all your keys are a single letter then you could use the ansi value by converting the character to it for the key...
something like: CStr(Asc("?")) [which is ugly but works].

--
Mark E Alsop



Tue, 09 Dec 2003 08:04:20 GMT  
 Collection.Add and Collection.Item question?
When using the Item method, it's "case insensitive", though that means a bit
more than just upper or lower case.

Tom Winter



Tue, 09 Dec 2003 21:55:07 GMT  
 Collection.Add and Collection.Item question?
Except if you then needed to use "ae" and "ae2" as keys...
they would convert to "ae2" and "ae2" causing duplicate
keys...

You would need to do a replace on "?" replacing it with
some string combination you know could never show up
naturally in the key.  That would depend on the situation
you are using it on.... Or try using a dictionary object.

Quote:
>-----Original Message-----
>Strange... maybe you stubbled onto a bug.. report it and
see what happens..

>For a work around, I got this to work..
>'==============
>   Dim strings As New Collection
>   Dim s As String

>   s = "?"
>   strings.Add s, s & Len(s)
>   s = "ae"
>   strings.Add s, s & Len(s)
>   MsgBox strings("ae2")

>   s = "?"
>   MsgBox strings(s & Len(s))

>   s = "ae"
>   MsgBox strings(s & Len(s))
>'==============

>a bit more work than it should be but... at least, you're
not stuck dead in
>your tracks..



>> I've got this simple code:

>> Private Sub Command1_Click()
>>     Dim strings As New Collection

>>     strings.Add "?", "?"
>>     MsgBox strings("ae")
>> End Sub

>> Incredibly the MsgBox strings("ae") statement actually
displays an "?"
>> letter. I'm not able to do:
>> Private Sub Command1_Click()
>>     Dim strings As New Collection

>>     strings.Add "?", "?"
>>     strings.Add "ae", "ae"
>> End Sub

>> This code fails as there's already an element with the
key "ae". It must
>> mean, that "?" is converted to "ae". Probably somebody
think this is
>smart.
>> From my point of view, it's obvious that no conversion
of the key argument
>> to the various collection methods is tolerable at all.

>> Do any of you know if I may do something to be able to

add both an "?" and

- Show quoted text -

Quote:
>> "ae" to the same collection?

>> Best regards,

>> Henrik

>.



Tue, 09 Dec 2003 23:12:44 GMT  
 Collection.Add and Collection.Item question?


Quote:
>The same results do not occur with ? and ce or ? and CE but they
>do occur with ce and CE so the collection object is not
>case-sensitive! To bad in mho since this greatly reduces the
>possible keys.

but it occurs with ? and OE and with ? and oe and with ? and ? and so
on.

AE and ? work, too.

Michael



Wed, 24 Dec 2003 04:43:35 GMT  
 Collection.Add and Collection.Item question?
Try the following

_______________________
Option Compare Text
Private Sub Form_Load()
MsgBox "?" = "ae"
End Sub

or
_______________________
Private Sub Form_Load()
MsgBox (StrComp("?", "ae", vbTextCompare) = 0)
End Sub

It returns "True"!
Same applies if I use "ss" = "?"
So collection keys are always "vbTextCompare"d. But why are "?" and
"ae" the same, and "?" and "ae" not?

Michael



Mon, 29 Dec 2003 06:33:02 GMT  
 Collection.Add and Collection.Item question?


Quote:
>Try the following

>_______________________
>Option Compare Text
>Private Sub Form_Load()
>MsgBox "?" = "ae"
>End Sub
>
>or
>_______________________
>Private Sub Form_Load()
>MsgBox (StrComp("?", "ae", vbTextCompare) = 0)
>End Sub
>
>It returns "True"!
>Same applies if I use "ss" = "?"
>So collection keys are always "vbTextCompare"d. But why are "?" and
>"ae" the same, and "?" and "ae" not?

>Michael

Suggestion from the left field: have you checked the actual ASCII
values of those...then check the UNICODE values for them and see what
gives UNICODE is two bytes long but some languages need four bytes to
proeprly describe their characters, so,,,).

We had like problems when checks were done on ASCII but the UNICODE
first word values was different (the problem was in a Thai machine
versus English)
============================================
If they even flap their meat at me, I will handle them
terminatedly (but legaly) as per the definition of the
word in their tech dict.
============================================



Thu, 08 Jan 2004 08:19:18 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. All items in my collection = the last item added

2. Collections, swapping items in a collection

3. VB Collections - Accessing the collection, not the item.

4. Collections, Collections and More Collections

5. Problems with adding Items in collections

6. ItemRemove event don't fire when removing last item in items collection object

7. newbie question: cannot Add User-defined type data to a Collection

8. ? Collection add object -> usercontrol add control

9. ? Collection add object -> usercontrol add control

10. Document collections and AllForms collections

11. Creating a CDO collection from an Outlook collection

12. using collection of collections

 

 
Powered by phpBB® Forum Software