forked from QB64-Phoenix-Edition/QB64pe
-
Notifications
You must be signed in to change notification settings - Fork 0
FOR (file statement)
Samuel Gomes edited this page Nov 8, 2022
·
1 revision
See OPEN.
FOR is used in a OPEN statement to indicate the file mode with which to open a file.
- If FOR isn't used in an OPEN statement, the default file mode RANDOM is used.
- APPEND - Keeps the information of the file intact while you can insert information at the end of it, writing permission only.
- BINARY - Opens the file in binary mode, use this with binary files.
- INPUT - Opens the file for viewing only.
- OUTPUT - The entire contents of the file is erased while you can put new information inside it, writing permission only.
- RANDOM - The default, you can get/put records defined by a record length (the variables type or LEN=length).
Warning: Make sure you don't have a file named test.tst before you run this or it will be overwritten.
CLS
OPEN "test.tst" FOR OUTPUT AS #1
PRINT #1, "If test.tst didn't exist:"
PRINT #1, "A new file was created named test.tst and then deleted."
PRINT #1, "If test.tst did exist:"
PRINT #1, "It was overwritten with this and deleted."
CLOSE #1
OPEN "test.tst" FOR INPUT AS #1
DO UNTIL EOF(1)
INPUT #1, a$
PRINT a$
LOOP
CLOSE #1
KILL "test.tst"
END
If test.tst didn't exist:
A new file was created named test.tst and then deleted.
If test.tst did exist:
It was overwritten with this and deleted.