Q. Can the "key" part of "Collection" be enumerated at all? 
Author Message
 Q. Can the "key" part of "Collection" be enumerated at all?

Hi,

I was wondering if the "key" portion of the Collection can be enumerated
like "item".

Assuming I have the following:

DIM newItem, newKey As String
DIM newCollection as New Collection

newCollection.Add newItem1, newKey1
...

I know we can retrieve newItem1 by

newCollection.Item(newKey1)

and that we can enumerate every item by

For i = 1 to newCollection(count)
    ... newCollection.Item(i)
next i

However, I would like to do something semantically similar to the
pseudo code below:

For each Key in newCollection
    ... show both newCollection.Item(Key) and newCollection.Key
next

However, unlike PERL which provides this functionality in a
data structure called Associate Array,
there's no such a method for the Key.

Any suggestions? Thanks.




Sat, 06 May 2000 03:00:00 GMT  
 Q. Can the "key" part of "Collection" be enumerated at all?

Quote:

>Hi,

>I was wondering if the "key" portion of the Collection can be enumerated
>like "item".

>Assuming I have the following:

>DIM newItem, newKey As String
>DIM newCollection as New Collection

>newCollection.Add newItem1, newKey1
>..

>I know we can retrieve newItem1 by

>newCollection.Item(newKey1)

>and that we can enumerate every item by

>For i = 1 to newCollection(count)
>    ... newCollection.Item(i)
>next i

>However, I would like to do something semantically similar to the
>pseudo code below:

>For each Key in newCollection
>    ... show both newCollection.Item(Key) and newCollection.Key
>next

>However, unlike PERL which provides this functionality in a
>data structure called Associate Array,
>there's no such a method for the Key.

>Any suggestions? Thanks.



Edwin,
    Some colleagues and I ran into the exact same problem.  The only work
around that we could come up with was to put a property in the object that
we added to the collection called Key.  So essentially we store the "key" in
two places: once in the collection index and once in the objects which are
part of the collection.  This isn't a real clean solution but it works.  We
are searching for a better way.

Mike

e.g:

    Dim colNames as New Collection
    Dim objMyName as New clsNameHolder

    objMyName.Name = "Smith, James"
    objMyName.Key = "sj022"

    colNames.Add objMyname, key:=objMyName.Key

   .
   .
   .

    For Each KeyField in colName
            Debug.Print KeyField.Name; KeyField.Key
    Next



Mon, 08 May 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. *"*-.,._,.-*"* I"LL TRADE VISUAL C++ FOR VBASIC *"*-.,_,.-*"*

2. Using collection.Item("key")

3. Detecting "Alt"+"Ctrl"+"Del" Key press

4. GetObject("","InternetExplorer.Application") fails in Excel VBA

5. SysCmd 603, "path","path"

6. Disabling "BACK"/"FORWARD" buttons

7. Loop print "VARIABLE", "VARIABLE"

8. DLL or something like "#"#ยค#"!"#

9. Disabling "BACK"/"FORWARD" buttons

10. CreateObject("Excel","//server"), MsgBox output

11. Problem With "window.showmodaldialog("")"

12. CreateObject("Excel","//server"), MsgBox output

 

 
Powered by phpBB® Forum Software