02-25-2026, 11:34 PM
OK and to round out this discussion here is finding a word or not (in same dictionary file as first post)
using Binary search and dandy handy Split Function.
using Binary search and dandy handy Split Function.
Code: (Select All)
_Title "Test FindW&() function" 'bplus 2026-02-25
Dim Shared CRLF$
CRLF$ = Chr$(13) + Chr$(10)
ReDim Shared words$(1)
Split _ReadFile$("Words.txt"), CRLF$, words$()
Print UBound(words$)
While 1
Input "Enter a word to see if in Collins Dictionary"; w$
If FindW&(w$) Then Print w$; ", is a word." Else Print w$; ", is Not a word"
Wend
Sub Split (SplitMeString As String, delim As String, loadMeArray() As String)
Dim curpos As Long, arrpos As Long, LD As Long, dpos As Long 'fix use the Lbound the array already has
curpos = 1: arrpos = LBound(loadMeArray): LD = Len(delim)
dpos = InStr(curpos, SplitMeString, delim)
Do Until dpos = 0
loadMeArray(arrpos) = Mid$(SplitMeString, curpos, dpos - curpos)
arrpos = arrpos + 1
If arrpos > UBound(loadMeArray) Then ReDim _Preserve loadMeArray(LBound(loadMeArray) To UBound(loadMeArray) + 1000) As String
curpos = dpos + LD
dpos = InStr(curpos, SplitMeString, delim)
Loop
loadMeArray(arrpos) = Mid$(SplitMeString, curpos)
ReDim _Preserve loadMeArray(LBound(loadMeArray) To arrpos) As String 'get the ubound correct
End Sub
Function FindW& (wd$)
Dim As Long lo, hi, m
Dim wrd As String: wrd = UCase$(wd$)
lo = 1: hi = 279423
While lo <= hi
m = (hi + lo) \ 2
If words$(m) = wrd Then
FindW& = m: Exit Function
ElseIf words$(m) < wrd Then
lo = m + 1
Else
hi = m - 1
End If
Wend
End Function
724 855 599 923 575 468 400 206 147 564 878 823 652 556 bxor cross forever

