Can you save files from qbasic
Guest
|
Post by Can you save files from qbasic on Nov 25, 2002 23:08:09 GMT
Is it possible to make a hiscores file using qbasic, that can be opened while the program is running, and where scores can be saved to?
|
|
Ziggi
Full Member
Posts: 87
|
Post by Ziggi on Nov 28, 2002 6:28:09 GMT
Yes ! And is very easy.
Here is example.:
' this part writes to the file with append to build up players history OPEN "c:\score.txt" FOR APPEND AS #100 WRITE #100, PLAYER$,SCORE$ CLOSE #100
' Reading from file 10 last records ( disply 10 last players) counter = 0 OPEN "c:\scores.txt" for input as 100 ' first step to count records in file DO WHILE NOT EOF(100) ' check if end of file LINE INPUT#100, TEST$ ' reading a whole line from file counter = counter + 1 ' incrising counter LOOP CLOSE 100
PRINT "Name","HI Score"
OPEN "C:\scores.txt" FOR INPUT AS #100 IF counter = 0 THEN PRINT " No HI scores !" :END IF counter <= 10 THEN FOR x=1 TO counter INPUT#100, HIPLAYER$ ,HISCORE$ PRINT HIPLAYER$ ,HISCORE$ NEXT x ELSEIF counter >10 THEN limit = counter - 10 FOR y=1 to limit ' omit some players to get last 10 LINE INPUT#100, TEST$ NEXT y FOR x=1 to 10 INPUT#100, HIPLAYER$,HISCORE$ PRINT HIPLAYER$ ,HISCORE$ NEXT x END IF CLOSE 100
END ' End of program
The list scores.txt is not sorted, you have to make sort section by score.
|
|