Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to format a While... Wend correctly?
#44
I haven't analyzed all those listings, but this seems to me to be the simplest search:
Code: (Select All)
Open "RA.txt" For Random As #1 Len = 11
bot = 0: top = LOF(1) \ 11 + 2: found = 0
Input "Word"; wrd$
wrd$ = UCase$(wrd$)
While Abs(top - bot) > 1
    srch = Int((top + bot) / 2)
    Get #1, srch, a$
    a$ = UCase$(a$)
    If a$ = wrd$ Then Print wrd$; " found at"; srch: found = 1: Sleep 2
    If a$ < wrd$ Then ' too low
        bot = srch
    Else
        top = srch
    End If
Wend
Close
If found = 0 Then Print "Not found": Sleep 2
Cls
Run

... using the binary search that bplus showed (amended/maybe corrupted a bit).
Works for me, anyway, including AA, ZEBRA, ZZZS and CAT!

(RA.txt is an RA file with len = 11)
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, Western Australia.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply


Messages In This Thread
RE: How to format a While... Wend correctly? - by PhilOfPerth - 03-02-2024, 03:51 AM



Users browsing this thread: 1 Guest(s)