Collection and keys 
Author Message
 Collection and keys

When I call an item in a collection I have trouble calling it by its key (a
string).The sytax does not force me to put a number in where as the keys are
stringa values and it should recall an item by its key string value.


Sat, 22 Nov 2003 23:23:19 GMT  
 Collection and keys
Try this code behind a command button:

Private Sub Command1_Click()
  Dim cList as Collection

  Set cList = New Collection

  cList.Add 1, "A"
  cList.Add 4, "B"
  cList.Add 9, "C"

  Msgbox cList.Item("B")
End Sub

Does clicking the message box pop-up a message box
with a 4 in it?


When I call an item in a collection I have trouble calling it by
its key (a
string).The sytax does not force me to put a number in where as
the keys are
stringa values and it should recall an item by its key string
value.



Sun, 23 Nov 2003 02:59:27 GMT  
 Collection and keys
hI,

If your keys are numeric then the collection access will be by index.  As a
workaround, ensure that your keys have an alpha character appended, both
when adding to the collection and when searching.

e.g.

colObjects.Add objItem, strKey & "K"

Set objItem = colObjects.Item(strSearchKey & "K")

Hope this helps,
Steve B


When I call an item in a collection I have trouble calling it by its key (a
string).The sytax does not force me to put a number in where as the keys are
stringa values and it should recall an item by its key string value.



Tue, 25 Nov 2003 00:01:27 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Collection Object Keys question

2. retrieving an item from a collection with key?

3. Why can I not access my collection by key

4. Invalid Procedure call when referencing collection by key

5. Invalid Procedure call when referencing collection by key

6. Newbie: Retrieving Collection Items KEY?

7. Reference Collections instance key

8. COLLECTIONS - Duplicate Keys

9. Retrieve collection.item key given the index

10. COLLECTIONS - Duplicate Keys

11. Retrieve key of a collection

12. Collection, Keys

 

 
Powered by phpBB® Forum Software