Re: Collection Capabilities
- From: "Brian" <bkstigler@xxxxxxx>
- Date: Wed, 9 May 2007 09:58:18 -0700
Thanks for the suggestions and sorry for the vague posting. The data and
properties are all string values. I just wanted a simpler way to sort and
process the sets.
My data is really like a recordset but is currently stored in a couple
collection objects. If I could host the data in a database... my life
would be a lot easier (but I don't have that option right now). So instead,
I just iterate through the collections to find the matching sets.
So I was really looking for something like the Recordset idea as applied to
a collection... (I'll look into that Olaf...)
Thanks,
Brian
"Schmidt" <sss@xxxxxxxxx> wrote in message
news:OtG5kYjkHHA.960@xxxxxxxxxxxxxxxxxxxxxxx
"Brian" <bkstigler@xxxxxxx> schrieb im Newsbeitrag
news:OIUkFyekHHA.744@xxxxxxxxxxxxxxxxxxxxxxx
I've got a problem...
I've got a collection of strings... the strings items can have two
additional "properties" for lack of a better word.
I would like to be able to sort the collection based on the
property or grab just those strings that have a particualr property set.
For instance... (hope the spacing looks reasonable)
String Prop1 Prop2
String1 a KK
String2 b JJ
String3 c FF
String4 b JJ
In this example... I would like to get a count of Strings with
the (b, JJ) property pair.
My first question is: Are collections the right way? What is a
better option verses just looping over the property types and
dumping the matching sets to an array?
You could use an unbound ADO-Recordset for this
purpose.
There you have a Filter-Property:
Rs.Filter = "Prop1='" & Str1 & "' AND Prop2='" Str2
Then your Rs reduces its Recorcount to the matching Records.
Another Option would be, to use my SortedDictionary-
Implementation from: http://www.thecommon.net/9.html
This "Collection-Replacement" contains the added Items
always sorted (by Key). The Key doesn't have to be unique
(.Unique-Property = False).
You could add your items in a loop with:
Key = Obj.Prop1 & "|" & Obj.Prop2
Dic.Add Key, Obj
All items will be sorted by this "combined Key", whilst adding.
Now you have very fast access to the matching items,
if you use something like this:
(carefully, this is "air-code")
KeyToSearch = "b|JJ"
Private Function DoFilter(KeyToSearch as String) as Collection
Dim CurIdx as Long
Set DoFilter = New Collection
If Not Dic.Exists(KeyToSearch) Then Exit Function
CurIdx = Dic.IndexByKey(KeyToSearch)
'first let's find the Top-Index of a sorted group
Do While CurIdx > 0
If Dic.KeyByIndex(CurIdx-1)<>KeyToSearch Then Exit Do
CurIdx = CurIdx - 1
Loop
'now we Loop over the sorted group from the top-entry
Do While CurIdx < Dic.Count
If Dic.KeyByIndex(CurIdx)<>KeyToSearch then Exit Do
'here we store all matching items in a VB-Collection
DoFilter.Add Dic.ItemByIndex(CurIdx)
CurIdx = CurIdx + 1
Loop
End Function
Olaf
.
- Follow-Ups:
- Re: Collection Capabilities
- From: Rick Rothstein \(MVP - VB\)
- Re: Collection Capabilities
- From: Schmidt
- Re: Collection Capabilities
- References:
- Collection Capabilities
- From: Brian
- Re: Collection Capabilities
- From: Schmidt
- Collection Capabilities
- Prev by Date: Re: Problems with MciSendString
- Next by Date: Re: Collection Capabilities
- Previous by thread: Re: Collection Capabilities
- Next by thread: Re: Collection Capabilities
- Index(es):
Relevant Pages
|