OPEN
Abbreviation: O <SHIFT+P>
TYPE: I/O Statement
FORMAT: OPEN <file-num>,[<device>][,<address>][,"<File-name>
[,<type>] [,<mode>]"]
Action: This statement OPENs a channel for input and/or output
to a peripheral device. However, you may NOT need all those parts
for every OPEN statement. Some OPEN statements require only 2
codes:
1) LOGICAL FILE NUMBER
2) DEVICE NUMBER
The <file-num> is the logical file number, which relates
the OPEN, CLOSE, CMD, GET#, INPUT#, and PRINT# statements to each
other and associates them with the file-name and the piece of
equipment being used. The logical file number can range from 1
to 255 and you can assign it any number you want in that range.
NOTE: File numbers over 128 were really designed for other
uses so it's good practice to use only numbers below 127 for file
numbers.
Each peripheral device (printer, disk drive, cassette) in the
system has its own number which it answers to. The <device>
number is used with OPEN to specify on which device the data file
exists. Peripherals like cassette decks, disk drives or printers
also answer to several secondary addresses. Think of these as
codes which tell each device what operation to perform. The device
logical file number is used with every GET#, INPUT#, and PRINT#.
If the <device> number is left out the computer will automatically
assume that you want your information to be sent to and received
from the Datassette(TM), which is device number 1. The file-name
can also be left out, but later on in your program, you can NOT
call the file by name if you have not already given it one. When
you are storing files on cassette tape, the computer will assume
that the secondary <address> is zero (0) if you omit the
secondary address (a READ operation).
A secondary address value of one (1) OPENs cassette tape files
for writing. A secondary address value of two (2) causes an end-of-tape
marker to be written when the file is later closed. The end-of-tape
marker prevents accidentally reading past the end of data which
results in the BASIC error message ?DEVICE NOT PRESENT.
For disk files, the secondary addresses 2 thru 14 are available
for data-files, but other numbers have special meanings in DOS
commands. You must use a secondary address when using your disk
drive(s). (See your disk drive manual for DOS command details.)
The <file-name> is a string of 1-16 characters and is optional
for cassette or printer files. If the file <type> is left
out the type of file will automatically default to the Program
file unless the <mode> is given.
Sequential files are OPENed for reading <mode>=R unless
you specify that files should be OPENed for writing <mode>
=W is specified. A file <type> can be used to OPEN an existing
Relative file. Use REL for <type> with Relative files. Relative
and Sequential files are for disk only.
If you try to access a file before it is OPENed the BASIC error
message ?FILE NOT OPEN will occur. If you try to OPEN a file for
reading which does not exist the BASIC error message ?FILE NOT
FOUND will occur. If a file is OPENed to disk for writing and
the file-name already exists, the DOS error message FILE EXISTS
occurs. There is no check of this type available for tape files,
so be sure that the tape is properly positioned or you might accidentally
write over some data that had previously been SAVED. If a file
is OPENed that is already OPEN, the BASIC error message FILE OPEN
occurs. (See Printer Manual for further details.)
EXAMPLES of OPEN Statements:
10 OPEN 2,8,4,"DISK-OUTPUT,SEQ,W" (Opens sequential
file on disk)
10 OPEN 1,1,2,"TAPE-WRITE" (Write End-of-File on
Close)
10 OPEN 50,0 (Keyboard input)
10 OPEN 12,3 (Screen output)
10 OPEN 130,4 (Printer output)
10 OPEN 1,1,0,"NAME" (Read from cassette)
10 OPEN 1,1,1,"NAME" (Write to cassette)
10 OPEN 1,2,0,CHR$(10) (open channel to RS-232 device)
10 OPEN 1,4,0,"STRING" (Send upper case/graphics
to the printer)
10 OPEN 1,4,7,"STRING" (Send upper/lower case to
printer)
10 OPEN 1,5,7,"STRING" (Send upper/lower case to
printer with device # 5)
10 OPEN 1,8,15,"COMMAND" (Send a command to disk)
|