Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to format a While... Wend correctly?
#28
I had removed the first two lines, my Collins.txt starts with AA word...

Steve I tested your code, but do not have version 3.12 installed yet so made my own _ReadFile function.

Your code seems to wrap around and I had to put a count = 279,496 limit to stop the thing from going around over and over WTH???
Code: (Select All)
dict$ = "Collins.txt"

Screen _NewImage(800, 600, 32)

Type Dict_Type
    As String Word, Definition
End Type

ReDim Shared Dict(3000000) As Dict_Type

load_time1# = Timer
temp$ = readfile$(dict$) ' <<<< made my own

'Print Mid$(temp$, 1, 500) ' test load
'Sleep
Dim As Long l, count, sp, ep
sp = 1
Do
    ep = InStr(sp, temp$, Chr$(13) + Chr$(10))
    temp1$ = Mid$(temp$, sp, ep - sp)
    'Print temp1$
    l = InStr(temp1$, Chr$(9)) 'tab separated data file

    count = count + 1


    Dict(count).Word = _Trim$(Left$(temp1$, l - 1))
    Dict(count).Definition = _Trim$(Mid$(temp1$, l + 1))
    'Print count, Dict(count).Word, sp, Len(temp$) ' <<<< 3,000,000 not enough WTH??? it's wrapping around and starting over??

    sp = ep + 2

Loop Until sp >= Len(temp$) Or count > 279496 ' <<<<<<  stop the insane wrap around!!!
load_time2# = Timer

ReDim _Preserve Dict(count) As Dict_Type

Dim Junk(10) As String
Data cheese,dog,cat,elephant,rootbeer,house,food,drink,zebra,mouse
For i = 1 To 10
    Read Junk(i)
Next


t# = Timer
For k = 1 To 10000
    For i = 1 To 10
        f = FindWord(Junk(i))
        If k = 1 Then 'no need to scroll the screen and print the words repeatedly
            If f = 0 Then
                Print Junk(i), "Word not found"
            Else
                Print Junk(i), Dict(FindWord(Junk(i))).Definition
            End If
        End If
    Next
Next
t1# = Timer

Print Using "###.######## seconds to load dictionary with ###,###,### words."; loadtimer2# - loadtime1#, count
Print Using "###.######## seconds to find #### words and definitions, ###,###,### repeated times."; t1# - t#, i - 1, k - 1

Function FindWord (word$)
    Dim As Long low, hi, test
    low = 1: hi = UBound(Dict)
    While low <= hi
        test = Int((low + hi) / 2)
        Select Case _StriCmp(Dict(test).Word, word$)
            Case 0
                'Print "found"; test
                FindWord = test: Exit Function
            Case -1
                'Print "low"; Dict(test).Word
                low = test + 1
            Case 1
                'Print "high"; Dict(test).Word
                hi = test - 1
        End Select
    Wend
End Function

Function readfile$ (f$)
    If _FileExists(f$) Then
        Open f$ For Binary As #1
        buff$ = Space$(LOF(1))
        Get #1, , buff$
        readfile$ = buff$
        Close #1
    End If
End Function

Zebra is found by your code and it does work well once the wrap around was fixed???
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Messages In This Thread
RE: How to format a While... Wend correctly? - by bplus - 02-29-2024, 04:36 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Need some help getting characters to follow each other correctly Cobalt 6 1,072 11-22-2024, 01:19 AM
Last Post: Cobalt
  Trasparent color not being set correctly here... Dav 9 1,567 11-10-2024, 04:11 AM
Last Post: bplus
  SHELL creates unicode file, can't read correctly with LINE INPUT thesolarcode 3 1,249 05-06-2023, 09:41 PM
Last Post: thesolarcode

Forum Jump:


Users browsing this thread: 1 Guest(s)