QB64 Phoenix Edition
Random Access word-list maker - 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: Programs (https://qb64phoenix.com/forum/forumdisplay.php?fid=7)
+---- Thread: Random Access word-list maker (/showthread.php?tid=2487)



Random Access word-list maker - PhilOfPerth - 03-06-2024

This is the prog I use now to generate Random Access word-lists for my games.
Not very elegant, but effective.  Maybe someone else will find it useful.

Thanks to bplus and others for help with RA.

Code: (Select All)
' RA Creator creates a Random Access file from the Collins Scrabble Dictionary, up to about 280000 words of 2 to 15 letters.
' Time taken should not exceed 10 seconds.
ScreenSetup:
Screen _NewImage(1120, 820, 32)
SetFont: f& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", 24, "monospace"): _Font f&
lhs = (_DesktopWidth - 1120) / 2
_ScreenMove lhs, 86 '                                                               centre display on screen
Common Shared CPL, CTR
CPL = 1120 / _PrintWidth("X")
DefLng A '                                                                          4 bytes allows for all word lengths

GEtANumber:
Input "Max Length (2 to 15)"; ML$ '                                                 select a max word length for RA file
ML = Val(ML$)
Cls
If ML < 2 Or ML > 15 Or ML <> Int(ML) Then GoTo GEtANumber '                        ML must be integer 2 - 15
FileName$ = "RA" + ML$: RecSize = ML + 4
Print "Creating RA file "; FileName$
Print
Open "words15.txt" For Input As #1 '                                                condensed dictionary with words up to 15 letters
Open FileName$ For Random As #2 Len = RecSize
While Not EOF(1)
    Input #1, wd$
    If Len(wd$) <= ML Then
        a = a + 1: Put #2, a, wd$
    End If
Wend
Print FileName$; " has"; a; "words, to"; ML; "letters max"

For b = 1 To 10
    Get #2, b, wd$: Print wd$
Next
Print
Print "Last word is ";
Get #2, a, wd$: Print wd$
Close
Sleep: Clear: Run