Skip to content

How programs input or output data

Thoroughbred Basic transfers data in and out through the use of logical channels. First, a device or file is connected to a specific numbered channel, and then communication can take place. In most cases, this connection is accomplished by an OPEN directive and terminated by a CLOSE directive (complete information on each directive is found in the Thoroughbred Basic Language Reference). For example:

OPEN (1) "LP"
connects the device LP, normally the name for the parallel printer, to the program's logical channel number 1.
OPEN (250) "#UTILS"
connects the file named #UTILS to logical channel number 250.

After a device or file is connected to a channel, all input and output operations need only refer to the channel number. There are two conditions where it is not necessary to issue an OPEN directive to connect a device to a channel for data transfer:

  • Each regular task (non-ghost task) always has its channel 0 open to its keyboard and terminal/monitor. Any attempt to OPEN or CLOSE this channel fails and may generate an error to the program.
  • Each ghost task always has its channel 0 open to provide communication with other tasks.

Once connection is made, data transfer can begin. There are several ways to receive data, each having its own Thoroughbred Basic directive. They are grouped into two categories based on the expected method of termination for each record of data taken in. The first two expect a record to be terminated by the carriage return character (hexadecimal 0D) or one of the function keys on the keyboard, if the keyboard is the input device:

INPUT
The simplest way to take in data, specifically designed for the keyboard.
FINPUT
Accepts data from the keyboard, displaying that data in a one-line window on the terminal screen, allowing for more characters of actual data to be taken in than could be shown in the window given.

Although these two directives expect a carriage return character or keyboard function key to terminate the data being taken in, this can be controlled by using I/O options in the actual directive to force a termination after a specific number of characters have been received. The remaining directives expect the device to terminate the data record by notifying the operating system (and Thoroughbred Basic) that the record is complete:

[P]READ
Inputs a data record from a file into the data variables specified by the program. PREAD is designed to read backwards through a file while READ is designed to go forward.
[P]EXTRACT
[P]READs a data record and sets a flag that prevents any other task from outputting data on top of the record in its file, until this task permits it. PEXTRACT processes the file backwards, EXTRACT in a forward direction.
FIND
If the specified data record is in the file, FIND behaves like the READ directive. However, if READ specifies a missing record, the file pointer is placed where the record should have been located. If FIND specifies a missing record, the file pointer does not move.

As with INPUT and FINPUT, these three directives can also force an end of record situation using some of the I/O options available in the directive, which provide for overriding the actual record size and forcing a new record size for input.

Thoroughbred Basic provides two directives to help you produce output:

PRINT
Outputs data to a device or file as a stream of characters, with no real understanding of the concept of fields or records. This is the normal directive used for outputs to printers and to the terminal. Thoroughbred Basic automatically places line feed codes, which normally contain the carriage return character, at the end of the string of characters, unless instructed by the directive to not do so.
WRITE
Outputs data in the form of a record. This is the most common directive used to output data to all file types.

Each of these directives for transfer of data has sub-commands that control the actual transfer and placement of the data. These vary from one file organization to another.

From the Thoroughbred Basic Developer Guide, version 8.9.1. Open this page in the PDF