Login
Plus/4 EncyclopediaFirstBackNextLast

OPEN Statement
Category
Reference/Commodore Basic V3.5

Topic
OPEN file#, device# [,secondary address] [,"filename,type,mode"]

The OPEN statement allows access to a peripheral device or to a tape or disk file.

The file number can be 0 to 255. Not all devices accept 0 as a file number. File numbers greater than 127 cause a line feed character to be sent after the carriage return at the end of a line, this is required by certain types of printers and RS-232 devices.

The device number identifies the device to be accessed. The default number is 1. The normal device numbers are as follows:
0: keyboard
1: tape
2: RS-232 port
3: screen
4-7: reserved for printers
8-11: reserved for disk drives

The usage of the secondary address depends on the device being accessed.
For the tape, 0: read from tape, 1: write to tape, 2: write to tape with END-OF-TAPE marker.
For printers, this is used to send commands. These vary between make and model of printer.
For disk drives, this indicates the channel being used.

The string following the secondary address may contain a command to a disk drive, or a filename on tape or disk. The type and mode components of the string are used for disk files only. (Types are: PRG, SEQ, REL and USR; modes are: READ and WRITE)

If an attempt is made to open a file that is already open, a ?FILE OPEN ERROR occurs.

Examples
OPEN 1,0 Opens the keyboard as a device
OPEN 3,3 Opens the screen as a device
OPEN 4,4 Opens a channel to use a printer
OPEN 1,1,0,"TEST" Opens the tape for reading and searches for the file named TEST
OPEN 15,8,15 Opens the command channel on a disk drive
OPEN 8,8,12,"TESTFILE,SEQ,WRITE" Creates a sequential disk file named TESTFILE for writing

Abbreviation
O SHIFT+P



Copyright © Plus/4 World Team, 2001-2024