RE: Fastest Selection
- From: Lorin <Lorin@xxxxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 23 Sep 2009 11:22:01 -0700
User entry is all up front and may come from a data file..
I tried these two methods.
Method 1
create two arrays.
loop through the key array and build a field of max length,
Then Lset each key into it own element and join into a long string
Then later at max program speed, use instr to locate the key.
Calculate the index of the item based on the fixed length of each element.
Use that index into the items to get the value.
Can be used with text or numeric items.
Method II
Just loop through the arrays until a match is found and use the key's index
to get the item at same index.
Results
Both are very fast but the Instr method typically is 20% faster.
After many runs of large loops (10,000) doing a search using both methods it
was unteresting to see that the speed and % difference varied all over the
place probably based on what Windows was up to at the time.
"Lorin" wrote:
I need to rapidly get a token from a string list..
e.g.
Dim sStr as String
Dim sToken as String
sStr = "Orange,Apple,Banna,Pear" ' this is a stub since the list can be
quite long.
sToken = "22,99,44,33" ' matching number of items in each
Both of these are user inputs so I do not immediately control the length of
each item.
Once set, these will not change for the app run.
If the user select Apple then token 99 should be returned.
If Orange, Apple were all the same length then I could get an index from an
Instr calculation, but they can be most any length.
Seems there must be something faster than a For Next loop of items set in
an array.
yes, VB6
suggestions please
- Follow-Ups:
- Re: Fastest Selection
- From: Nobody
- Re: Fastest Selection
- References:
- Fastest Selection
- From: Lorin
- Fastest Selection
- Prev by Date: Re: Webbrowser, Convert HTML to image
- Next by Date: Re: Win7
- Previous by thread: Re: Fastest Selection
- Next by thread: Re: Fastest Selection
- Index(es):
Relevant Pages
|
Loading