An OPEN statement assigns a file to a channel.
Channel_number is an numeric expression, and File_Name is a string expression below.
When a file name without an extension is assigned, if the file designated does not exist, the file name is assumed to have the extension ".TXT".
OPEN #Channel_Number : NAME File_Name ,ACCESS OUTIN
OPEN #Channel_Number : NAME File_Name
OPEN #1: NAME "A:ABC.TXT"
When the designated file does not exist, the file shall be newly created.
However if the drive name or the directory name is wrong, an exception of extype 7101 shall be raised.
Just after the execution of an OPEN statement, the file pointer points the beginning of the file.
In case of output using PRINT statements, it is necessary for beginning output either to erase the contents using a ERASE statement or to move the file pointer to the end using a SET POINTER END statement.
OPEN #Channel_Number : NAME File_Name ,ACCESS INPUT
opens the file only for input.
If the designated file does not exist, an exception of extype 7102 shall be raised.
When a ERASE statement or a PRINT statement is executed, an exception shall be raised (extype7301,7302）.
OPEN #Channel_number : NAME File_Name ,ACCESS OUTPUT
opens the file only for output.
The file pointer points the end.
If the file designated does not exist, the file shall be created.
If a ERASE statement or a INPUT statement is executed, an exception shall be raised(extype7301,7303).
If SET POINTER BEGIN has been executed, an exception may raised when a PRINT statement is executed.
Thus, an OPEN-ACCESS-OUTPUT statement is used for appending output.
Channel numbers greater than 0 are independent for each program unit.
A Channel can be made a parameter of an external subprogram.
100 DECLARE EXTERNAL SUB s1 110 OPEN #1:NAME "A:TEST1.TXT" 120 CALL s1(#1,"ABC") 130 CLOSE #1 140 END 200 EXTERNAL SUB s1(#2,s$) 210 PRINT #2:s$ 220 END SUB
The console is assigned to #0 beforehand. That is, input or output for #0 are the same as those written omitted a channel expression. No OPEN statement is needed for #0.
Refer to COM-port (serial port)