Re: Collection Capabilities



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




.



Relevant Pages

  • Re: Collection Capabilities
    ... I've got a collection of strings... ... Now you have very fast access to the matching items, ... Dim CurIdx as Long ... 'now we Loop over the sorted group from the top-entry ...
    (microsoft.public.vb.general.discussion)
  • Speed comparison of regex versus index, lc, and / /i
    ... "index" is better for matching fixed strings than using regular ... As a test of the proposition that index is better than regexes, ... doing the matching, rather than converting the strings using lc, saved ... spent converting to lower case. ...
    (comp.lang.perl.misc)
  • Re: Speed comparison of regex versus index, lc, and / /i
    ... "index" is better for matching fixed strings than using regular ... As a test of the proposition that index is better than regexes, ... doing the matching, rather than converting the strings using lc, saved ... spent converting to lower case. ...
    (comp.lang.perl.misc)
  • Re: OT: novice regular expression question
    ... >> data record begins with either a string, or a list of strings. ... If the format is "Python strings and lists of ... Then use that pattern, parenthesized to turn it ... > Let's try matching a single string first: ...
    (comp.lang.python)
  • Re: OT: novice regular expression question
    ... > data record begins with either a string, or a list of strings. ... If the format is "Python strings and lists of ... "negative lookbehind assertion" - in other words, a pattern that doesn't ... Let's try matching a single string first: ...
    (comp.lang.python)