s***@yahoo.com
2013-05-07 21:22:36 UTC
Hi folks,
I am just trying to get my head around using the For Each ... to recurse through a custom Collection object. This is my first use of these tools.
I can't seem to see a way to derive the "KEY" value assigned to a member of the collection while using the For Each approach. The Default property of the collection object is the "ITEM" value.
Declared in a module:
Public colObject as New Collection
Form code:
Dim varValue As Variant
Dim strValue As String
'Build simple collection
colObject.Add "myItem01", "myKey01"
colObject.Add "myItem02", "myKey02"
colObject.Add "myItem03", "myKey03"
colObject.Add "myItem04", "myKey04"
For Each varValue In colObject
'This grabs the [Item] value because it is the default property.
strValue=CStr(varValue)
Next
I don't see a way to determine the "KEY" value. Use of the KEY value would help me compare one collection to another collection. My ultimate goal is to use the speed of "For Each" with collections to quickly compare two large textual datasets for discrepancies. I want to stay away from connections and dependencies to SQL databases/services, and very much prefer to have a simple 100 kb application perform such a task.
I realize I can enter the KEY value in BOTH the KEY & ITEM entries to get my end result, but it doubles the data size of the collection.
Any insight is appreciated.
Thanks.
~Steve
I am just trying to get my head around using the For Each ... to recurse through a custom Collection object. This is my first use of these tools.
I can't seem to see a way to derive the "KEY" value assigned to a member of the collection while using the For Each approach. The Default property of the collection object is the "ITEM" value.
Declared in a module:
Public colObject as New Collection
Form code:
Dim varValue As Variant
Dim strValue As String
'Build simple collection
colObject.Add "myItem01", "myKey01"
colObject.Add "myItem02", "myKey02"
colObject.Add "myItem03", "myKey03"
colObject.Add "myItem04", "myKey04"
For Each varValue In colObject
'This grabs the [Item] value because it is the default property.
strValue=CStr(varValue)
Next
I don't see a way to determine the "KEY" value. Use of the KEY value would help me compare one collection to another collection. My ultimate goal is to use the speed of "For Each" with collections to quickly compare two large textual datasets for discrepancies. I want to stay away from connections and dependencies to SQL databases/services, and very much prefer to have a simple 100 kb application perform such a task.
I realize I can enter the KEY value in BOTH the KEY & ITEM entries to get my end result, but it doubles the data size of the collection.
Any insight is appreciated.
Thanks.
~Steve