Re: Listbox / Database Question

Tech-Archive recommends: Fix windows errors by optimizing your registry



On Sat, 26 Nov 2005 06:40:02 -0800, "=?Utf-8?B?TWljcm9za2lsbHM=?="
<Microskills@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

>Thanks J;
>I've found code for virtual Listboz implementation. I think I am going to
>implement that.

That makes sense

>You say "personally I would use an assisted binary chop driven by a search
>key built in the key down event of a Usercontrol containing the VLB"

>what is this? and where can i find sample code?

If you have a sorted list of items then you can find one specific item
by cutting the list in half repeatedly eg:

Looking for K in

A C D G H J K L M

Read middle key - H is K bigger, smaller or equal to K ?

H is smaller so our minimum is H and we examine the middle of

H J K L M which is K so we have a hit

If you have the records on disk, you can speed things up by holding
say, every 1000'th key in memory

Here is a simple BChop for finding the position of a small key in a
long string of keys of the same length
eg:

Find: HH in AABBCCDDEEFFHHKKMMNNZZ

' ###########################################
'
' Returns Nearest Match Position within String or beyond
'
Function BChopStrPos&(TheKey$, MainString$)
Dim Min&, Max&, N&, KeyLen&, Pos&, Gap&

KeyLen& = Len(TheKey$)
Min = 1
Max = Len(MainString$) / KeyLen
Gap = Max

While Gap > 0
Gap = (Max - Min) / 2
N = Min + Gap
Pos = (N - 1) * KeyLen + 1
If Mid$(MainString$, Pos, KeyLen) > TheKey$ Then
Max = N
Else
Min = N
End If
' --- Speed Exit
Pos = (Min - 1) * KeyLen + 1
If Mid$(MainString$, Pos, KeyLen) >= TheKey$ Then
Max = Min
End If
Wend
' --- Return Key Above
Pos = (Max - 1) * KeyLen + 1
If Mid$(MainString$, Pos, KeyLen) < TheKey$ Then
Pos = Pos + KeyLen
End If
BChopStrPos = Pos
End Function

====================================================

Here is another version for finding a Key in an Array

Function FindKeyPos&(Start&, Max&, TheKey$)
Dim N&
' ---
If TheKey$ <= Key$(Start) Then
FindKeyPos = Start
Exit Function
End If
' ---
If TheKey$ > Key$(Max) Then
FindKeyPos = Max + 1
Exit Function
End If
' ---
N = Start + Int((Max - Start) / 2)
If TheKey$ < Key(N) Then
N = FindKeyPos&(Start& + 1, N, TheKey$)
Else
N = FindKeyPos&(N, Max - 1, TheKey$)
End If
FindKeyPos = N
' Key$( N ) is greater or equal to TheKey$
End Function



In your case I would keep all your words in a Text file
- sort the Text file using :-
http://www.jerryfrench.co.uk/dsortv.htm

Then I would treat the text file like a Random Access file using :-
http://www.jerryfrench.co.uk/etxtmgr.htm

Both are Delphi DLLs, I suspect that you cannot use etxtmgr in VB.NET
as it uses Variants, but reading the description will give you an
idea.
Anyway, you probably only need to build the 'index' when the word list
has changed, which will not be every time the App is run.





.