mirror of
https://github.com/QB64Official/qb64.git
synced 2024-08-30 16:30:15 +00:00
62 lines
2 KiB
Text
62 lines
2 KiB
Text
|
{{KW|FOR (file statement)|FOR}} is used in a {{KW|OPEN}} statement to select the filemode to open the file with.
|
||
|
|
||
|
|
||
|
{{PageSyntax}}
|
||
|
:{{KW|OPEN}} ... {{KW|FOR (file statement)|FOR}} {APPEND|BINARY|INPUT|OUTPUT|RANDOM}
|
||
|
|
||
|
|
||
|
{{PageDescription}}
|
||
|
|
||
|
* If {{KW|FOR (file statement)|FOR}} isn't used in a {{KW|OPEN}} statement then the default filemode {{KW|RANDOM}} is used.
|
||
|
** {{KW|APPEND}} - Keeps the information of the file intact while you can insert information at the end of it, writing permission only.
|
||
|
** {{KW|BINARY}} - Opens the file in binary mode, use this with binary files.
|
||
|
** {{KW|INPUT (file mode)|INPUT}} - Opens the file for viewing only.
|
||
|
** {{KW|OUTPUT}} - The entire contents of the file is erased while you can put new information inside it, writing permission only.
|
||
|
** {{KW|RANDOM}} - The default, you can get/put records defined by a record length (the variables type or LEN=length).
|
||
|
|
||
|
|
||
|
{{PageExamples}}
|
||
|
'''Warning:''' ''Make sure you don't have a file named test.tst before you run this! It will be overwritten if so!''
|
||
|
|
||
|
{{CodeStart}}
|
||
|
|
||
|
{{Cl|CLS}}
|
||
|
|
||
|
{{Cl|OPEN}} "test.tst" {{Cl|FOR (file statement)|FOR}} {{Cl|OUTPUT}} {{Cl|AS}} #1
|
||
|
{{Cl|PRINT (file statement)|PRINT}} #1, "If test.tst didn't exist:"
|
||
|
{{Cl|PRINT (file statement)|PRINT}} #1, "A new file was created named test.tst and then deleted."
|
||
|
{{Cl|PRINT (file statement)|PRINT}} #1, "If test.tst did exist:"
|
||
|
{{Cl|PRINT (file statement)|PRINT}} #1, "It was overwritten with this and deleted."
|
||
|
{{Cl|CLOSE}} #1
|
||
|
|
||
|
{{Cl|OPEN}} "test.tst" {{Cl|FOR (file statement)|FOR}} {{Cl|INPUT (file mode)|INPUT}} {{Cl|AS}} #1
|
||
|
{{Cl|DO}} {{Cl|UNTIL}} {{Cl|EOF}}(1)
|
||
|
{{Cl|INPUT (file statement)|INPUT}} #1, a$
|
||
|
{{Cl|PRINT}} a$
|
||
|
{{Cl|LOOP}}
|
||
|
{{Cl|CLOSE}} #1
|
||
|
|
||
|
{{Cl|KILL}} "test.tst"
|
||
|
|
||
|
{{Cl|END}}
|
||
|
|
||
|
{{CodeEnd}}
|
||
|
|
||
|
{{OutputStart}}
|
||
|
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.
|
||
|
{{OutputEnd}}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
{{PageSeeAlso}}
|
||
|
* {{KW|OPEN}}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
{{PageNavigation}}
|