A simple sequential file will do it...

by (Login qb432l)
Mod

 

OPEN "File.DAT" FOR APPEND AS #1
CLOSE #1

'These first lines will create a file if none exists, but will not alter
'the file if it exists. Without it, you would get an error the first time
'the program is run. Then:

OPEN "File.DAT" FOR INPUT AS #1
IF NOT EOF(1) THEN INPUT #1, NumRuns
CLOSE #1

'If the program has already been run, NumRuns will represents the number
'of times the program was run. If the program hasn't been run yet, the
'value of NumRuns will be 0. Incidentally, "IF NOT EOF(1)" prevents another
'possible file error if no value has been stored yet in the file.

NumRuns = NumRuns + 1
PRINT NumRuns

'The value of the variable NumRuns increases by 1 each time the program is
'run.

OPEN "File.DAT" FOR OUTPUT AS #1
WRITE #1, NumRuns
CLOSE #1

'Now the file "File.DAT" contains a variable which reflects the number of
'times the program has been run. Copy these lines of code and run the program
'over and over. You'll notice that each time it runs, the value of NumRuns
'will be printed. Notice that it increases by 1 each time. Turn off your computer
'and then when it reboots, run the program again. You'll notice that the previous
'value was saved until the next time the program was run.

'-Bob



    
This message has been edited by qb432l on Feb 27, 2012 10:30 AM

Posted on Feb 27, 2012, 10:22 AM

Respond to this message   

Return to Index

Response TitleAuthor and Date
Help Qbasic on Feb 28
Re: A simple sequential file will do it... on Feb 28
 *Sorry Paulo, can't help you there. Maybe someone else in the forum knows. on Feb 28
 You can use SHELL with Notepad to print text files. on Feb 28
  You can use SHELL with Notepad to print text files on Mar 1
   Help Qbasic printing file on Mar 5
    Is that all that is in the file? on Mar 5

 Copyright © 1999-2014 Network54. All rights reserved.   Terms of Use   Privacy Statement