QB64 Phoenix Edition
How to format a While... Wend correctly? - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10)
+---- Thread: How to format a While... Wend correctly? (/showthread.php?tid=2466)

Pages: 1 2 3 4 5


RE: How to format a While... Wend correctly? - PhilOfPerth - 02-29-2024

(02-29-2024, 03:21 PM)bplus Wrote: Here is my RA method tested with zebra and some of your words, no rootbeer here either but does find zebra OK


Possible Plil's list was reassembled from his letter lists???

Mine came straight from Collins 2019 Scrabble which came from you Steve, I think?

No, the list was a direct download from the 'net, without sorting (but I did filter my  own lists for shorter words and to remove some "F'" and "C" words, to make it suitable for general consumption.


RE: How to format a While... Wend correctly? - PhilOfPerth - 02-29-2024

(02-29-2024, 02:53 PM)bplus Wrote: cat = to vomit??? that's what a cat is?

I gotta check my Collin's now ;-))

That's a weird definition. I searches several dictiomaries and couldn't match it, but a search on VOMIT came up with a slang phrase, "to shoot the cat". Huh 
That's as close as I can get!


RE: How to format a While... Wend correctly? - SMcNeill - 02-29-2024

(02-29-2024, 06:33 PM)bplus Wrote: So something else is going on that using count to control stop fixes.

BTW .39 +/-  secs to load dictionary well within acceptable range!
I think the issue you're seeing is from the last line being blank. I don't think it terminates with a chr$(10), so you're never actually advancing to the end of the file.

Add a check for If temp1$ = "" Then Exit Do in there, and you're golden.

Your endless loop is basically start point = 1234567890, end point = 0... then at the end of that loop, start point = end point + 1... so it just starts reading the whole file over and over and over and over and over and over again.

Exit it with a check for that blank line, and you skip that reset to 0. Wink


RE: How to format a While... Wend correctly? - SMcNeill - 02-29-2024

(02-29-2024, 11:23 PM)PhilOfPerth Wrote:
(02-29-2024, 02:53 PM)bplus Wrote: cat = to vomit??? that's what a cat is?

I gotta check my Collin's now ;-))

That's a weird definition. I searches several dictiomaries and couldn't match it, but a search on VOMIT came up with a slang phrase, "to shoot the cat". Huh 
That's as close as I can get!

https://en.wiktionary.org/wiki/cat#Verb

(02-29-2024, 11:03 PM)PhilOfPerth Wrote:
(02-29-2024, 03:21 PM)bplus Wrote: Here is my RA method tested with zebra and some of your words, no rootbeer here either but does find zebra OK


Possible Plil's list was reassembled from his letter lists???

Mine came straight from Collins 2019 Scrabble which came from you Steve, I think?

No, the list was a direct download from the 'net, without sorting (but I did filter my  own lists for shorter words and to remove some "F'" and "C" words, to make it suitable for general consumption.

The problem wasn't with the list.  It was with SINGLE losing precision counting character position with the list.  A single variable type can only got up to 16.3 million or so, before it swaps over to scientific notation.  The file is over 17 million bytes in size, and thus the issue I was having.  Wink

You still might want to grab the version I posted as an attachment a few versions up.  It cleans out those 2 header lines and removes a blank line at the end, and makes it so you only have to look for CHR$(10) line endings instead of chr$(13) + chr$(10), which reduces overall size by 275k bytes.  (one byte for each line in the file.)


RE: How to format a While... Wend correctly? - bplus - 02-29-2024

(02-29-2024, 11:27 PM)SMcNeill Wrote:
(02-29-2024, 06:33 PM)bplus Wrote: So something else is going on that using count to control stop fixes.

BTW .39 +/-  secs to load dictionary well within acceptable range!
I think the issue you're seeing is from the last line being blank. I don't think it terminates with a chr$(10), so you're never actually advancing to the end of the file.

Add a check for If temp1$ = "" Then Exit Do in there, and you're golden.

Your endless loop is basically start point = 1234567890, end point = 0... then at the end of that loop, start point = end point + 1... so it just starts reading the whole file over and over and over and over and over and over again.

Exit it with a check for that blank line, and you skip that reset to 0. Wink

+1 That sounds so likely and nicely reasoned I don't even want to test and find out it's wrong. ;-))
I've been working on getting v3.12 loaded and copying my 13,994 files and 1051 folders to a backup drive and before that, storing away or dumping 2 months of files and pictures, whew!

Confirmed, I tested by ending loop with this:
Code: (Select All)
Loop Until sp >= Len(temp$) Or ep = 0



RE: How to format a While... Wend correctly? - SpriggsySpriggs - 03-01-2024

At a certain point, dealing with a dictionary of that size sounds better suited for a SQLite database.


RE: How to format a While... Wend correctly? - mdijkens - 03-01-2024

This file is so small, just keep it in a small corner of your memory
Makes life much easier also.

Takes 39ms on my older i5 system:
Code: (Select All)
Dim Shared words As String
words = _ReadFile$("Collins.txt")

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(.001)
For i = 1 To 10
  Print Junk(i),
  def$ = FindWord(Junk(i))
  If def$ = "" Then
    Print "Word not found"
  Else
    Print def$
  End If
Next
t1# = Timer(.001)
Print Using "###.######## seconds to find #### words and definitions"; t1# - t#, i - 1
' 0.039 seconds

Function FindWord$ (wrd$)
  fpos& = InStr(words, UCase$(wrd$) + Chr$(9))
  If fpos& > 0 Then
    fpos& = fpos& + Len(wrd$) + 1
    eol& = InStr(fpos&, words, Chr$(13))
    FindWord$ = Mid$(words, fpos&, eol& - fpos&)
  End If
End Function



RE: How to format a While... Wend correctly? - bplus - 03-01-2024

Oh that looks pretty nice and efficient, way to use that tab char!

OK I was testing that function and it found another definition for CAT:
Code: (Select All)
Dim Shared words As String
words = _ReadFile$("Collins.txt")

Do
    Input "Enter word to lookup "; lookup$
    result$ = FindWord$(lookup$)
    If result$ = "" Then Print lookup$; " Not Found." Else Print result$
    Print
Loop Until lookup$ = ""

Function FindWord$ (wrd$) ' thanks mdijkens
    fpos& = InStr(words, UCase$(wrd$) + Chr$(9))
    If fpos& > 0 Then
        fpos& = fpos& + Len(wrd$) + 1
        eol& = InStr(fpos&, words, Chr$(13))
        FindWord$ = Mid$(words, fpos&, eol& - fpos&)
    End If
End Function
   

So it found cat somewhere else in Collins.txt???

I verified the Collins def of CAT as 'to vomit' so how are we finding this new definition?

Also mouse looked different.


RE: How to format a While... Wend correctly? - SMcNeill - 03-01-2024

You're getting the 2nd half of "alley cat" definition.

Which is why a look up list is better than a INSTR search.  Wink

You might try to search for CHR$(10) + word$ + CHR$(9), for the line ending from the previous line, plus the word, with the tab separator after.


RE: How to format a While... Wend correctly? - bplus - 03-01-2024

that might work except for AA but who cares about that
;-))

I am starting to think the RA method wasn't too terrible Smile 0 preprocessing after setup RA, but yes some duplication and 2 files for words...
The definitions doesn't even have to be RA.