Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Function IsWord%(test$)
#5
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.
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
Reply


Messages In This Thread
Function IsWord%(test$) - by bplus - 02-25-2026, 08:58 PM
RE: Function IsWord%(test$) - by SMcNeill - 02-25-2026, 09:27 PM
RE: Function IsWord%(test$) - by SMcNeill - 02-25-2026, 10:16 PM
RE: Function IsWord%(test$) - by SMcNeill - 02-25-2026, 10:25 PM
RE: Function IsWord%(test$) - by bplus - 02-25-2026, 11:34 PM
RE: Function IsWord%(test$) - by mdijkens - 02-26-2026, 02:51 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Zeller's congruence pass 3: test day-of-week calculation algorythms for accuracy TDarcos 0 1,112 10-23-2024, 05:04 PM
Last Post: TDarcos
  Test sorting algorithms eoredson 3 1,001 05-04-2023, 09:38 PM
Last Post: eoredson
  Long Date Function AtomicSlaughter 2 1,000 05-24-2022, 08:22 PM
Last Post: bplus

Forum Jump:


Users browsing this thread: