02-08-2023, 03:09 AM
A working version which showcases how this would work with a real file, and also why one might want to have that SEEK in the program.
Grab the dictionary file here:
unixdict.7z (Size: 63.66 KB / Downloads: 49)
Now, when you first run this, it'll quickly let you know that there's only 3500 or so groups of 7 words in this dataset... Yet, we were told to print 4000 sets of 7, so this has to do a little error checking for that -- and it does.
We open the file. Set the datacount to 0. Run a file counter just 'cause... (mainly to showcase why SEEK might be used rather than repeated OPEN and CLOSE.) I made the file counter recursive as well, just for the heck of it. Reset the datacount to 0. Run the recursive routine to get the actual data. Print the data, pause when the screen is fullish. Recursively repeat until finished.
And that's the who shebang in a nutshell -- Recursive, SEEKING, file INPUT, data-driven program.
Code: (Select All)
SCREEN _NEWIMAGE(800, 600, 32)
DIM SHARED AS LONG DataCount
DIM SHARED AS STRING DataItem(7)
OPEN "unixdict.txt" FOR INPUT AS #1
resetDataCount
filecount
PRINT "There are"; DataCount; "full groups of 7 entries in this database."
PRINT "Press <ANY KEY> to see the first 4000 groups of 7 entries."
SLEEP
resetDataCount
Recur
SUB resetDataCount
DataCount = 0
END SUB
SUB filecount
IF DataCount = 0 THEN SEEK #1, 1 'move to the start of the file 'may need to change to 0 for 0 index counting
FOR j = 1 TO 7
IF EOF(1) THEN EXIT SUB
INPUT #1, junk$
NEXT
DataCount = DataCount + 1
filecount
END SUB
SUB Recur
IF DataCount = 0 THEN SEEK #1, 1
FOR i = 1 TO 7
IF NOT EOF(1) THEN INPUT #1, DataItem(i) ELSE DataItem(i) = ""
NEXT
DataCount = DataCount + 1
PRINT DataCount; ")";
CALL WorkSub
IF DataCount < 4000 THEN Recur
END SUB
SUB WorkSub
STATIC pagecount
FOR i = 1 TO 7
PRINT DataItem(i); ", ";
NEXT
PRINT
pagecount = pagecount + 1
IF pagecount = 33 THEN
pagecount = 0
PRINT "Press <ANY KEY> to continue."
SLEEP
END IF
END SUB
Grab the dictionary file here:
unixdict.7z (Size: 63.66 KB / Downloads: 49)
Now, when you first run this, it'll quickly let you know that there's only 3500 or so groups of 7 words in this dataset... Yet, we were told to print 4000 sets of 7, so this has to do a little error checking for that -- and it does.
We open the file. Set the datacount to 0. Run a file counter just 'cause... (mainly to showcase why SEEK might be used rather than repeated OPEN and CLOSE.) I made the file counter recursive as well, just for the heck of it. Reset the datacount to 0. Run the recursive routine to get the actual data. Print the data, pause when the screen is fullish. Recursively repeat until finished.
And that's the who shebang in a nutshell -- Recursive, SEEKING, file INPUT, data-driven program.