PRB: Key in VBA Collection Object Is Not Case-Sensitive

ID: Q189251

The information in this article applies to:

SYMPTOMS

When trying to add or retrieve an element of a Collection using the Key property, the Key value is not case-sensitive. This is inconsistent with Collections elsewhere in Visual Basic.

RESOLUTION

If you need a Collection with a case-sensitive key, use the Dictionary Object. The Dictionary is quite similar to a Collection, but offers expanded functionality. For additional information, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q187234
   TITLE     : Use the Dictionary Object with Visual Basic


STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior:

1. Start a new Standard EXE project in Visual Basic. Form1 is created by

   default.

2. Add the following code to the Form_Load event of Form1:

      Dim col As New Collection
      col.Add Key:="TEST", Item:="some data"
      col.Add Key:="Test", Item:="more data"

3. Run the project. You should see:

      "Runtime Error '457': This Key is already associated with an element
      of this Collection."

Additional query words: kbDSupport kbDSD kbvba kbVBp400 kbVBp500 kbNoKeyWord
Keywords          :  
Version           : WINDOWS:4.0,5.0
Platform          : WINDOWS
Issue type        : kbprb

Last Reviewed: May 18, 1999