Print

From BR Wiki
Jump to navigation Jump to search

See also Print (disambiguation)

The Print (PR) statement sends "unformatted" output to the console, a printer, a display file, a communications file, a window file or another device assigned by an Open display statement.

If BR is running in UNATTENDED mode: OPEN #253: redirects console PRINT output to this channel. This means you can capture your console PRINT strings.

Comments and Examples

The Print statement considers the screen and the system printer to be display files; these two devices do not require OPEN statements before they can be accessed with PRINT statements. Special device file numbers are 255 for the printer and 0 for the screen.

In the following example, lines 110 and 120 are equivalent for printing to the screen.

00110 PRINT #0: "The total is  -"; TOTAL
00120 PRINT "The total is  -"; TOTAL

Other devices, printers, and modems which require ASCII characters as output may also be opened as display files, then sent data by the PRINT statement.

03250 PRINT #255 using addressform: name1$,name2$,address$,city$,state$,zip
03255 addressform: c 10,c 10, c 25,c 25,c 2,n 7

The above example will print an address to the printer.

The keyword BELL is used to sound a bell or tone generator. In the following example, line 130 produces a beep from the screen, and line 140 produces a tone or bell from the printer (if supported on that model printer):

00130 PRINT BELL
00140 PRINT #255: BELL

In the following example, the NEWPAGE keyword clears the screen (line 150) and advances the printer to the top of a page (line 160):

00150 PRINT NEWPAGE
00160 PRINT #255: NEWPAGE

Line 160 also resets the PAGEOFLOW counter and the KREC(255) function to zero.

There are two methods of unformatted printing. The first is called zone printing and is signaled by the comma used as a separator. When items in a PRINT statement without USING are separated by commas, they will begin in zones starting in column 1. A new zone starts every 24 columns. In the following example, line 170 prints an A in column 1 of the screen, a 2 in column 25, a -2 in column 49, and a B in column 1 of the next line:

00170 PRINT "A", 1, -2, "B"

Another method of unformatted printing is to override zone printing by using a semi-colon (;) as a separator between items to be printed. With a semi-colon, string items always print immediately next to each other, and numeric items always generate a leading and trailing space. In the next example, line 180 differs from the previously listed line 170 only in that the commas have been replaced by semi-colons -yet the output differs considerably. Line 180 prints an A in column 1 of the screen, a 1 in column 3, a -2 in column 6, and a B in column 9 of the next line:

00180 PRINT "A"; 1; -2; "B"

Syntax

PRINT #{<file number>|<window number>} : {[]|[ MAT <array name>]|[ TAB(<numeric expression>)]|[ NEWPAGE ]|[ BELL ]}[{,|;}...] [<error condition> <line ref>][,...]

Defaults

1.) Output to the screen.
2.) Null data item.
3.) Interrupt the program if an error occurs and "ON error" is not active.

Parameters

The optional "file-num" and "wind-num" parameters identify the output location for the printed information. The integer or numeric expression that is specified must match the specification used in the OPEN statement for the same file, device or window. Two exceptions are that PRINT #255 and PRINT #0 can be used without an explicit OPEN statement. PRINT #255 outputs to the system printer, and PRINT #0 outputs to the screen.

The "data-item" and "MAT array name" parameters identify the items to be output. "TAB (num-expr)" aligns data at the column indicated by the "num-expr". TAB (x) positions the cursor at column x (similar to POS in a FORM statement), where x is any numeric expression. If the current position of the line is greater than column x, the cursor is positioned at column x in the next line. If x is negative, TAB(1) is assumed. If x is not an integer, it is rounded. If x is greater than the record length, the cursor is positioned at column 1 in the next line.

The "BELL" parameter sounds the bell or tone generator for the screen or printer. PRINT BELL is equivalent to PRINT CHR$(7) (the ASCII value for BEL).

The "NEWPAGE" parameter performs according to the output location. When output is to the screen, NEWPAGE erases the screen and positions the cursor at the bottom left corner. When output is to a printer, NEWPAGE advances the paper to the top of the page. If the "file-num" is not zero, NEWPAGE also resets the KREC function to zero. PRINT NEWPAGE is equivalent to PRINT CHR$(12) (the ASCII value for FF, or form feed).

Multiple specifications of "data-item", "MAT array name", "TAB", "BELL" and "NEWPAGE" may be separated with either commas or semi-colons. The position of each data-item is determined by the separator that precedes it. Commas cause the output to be zone printed in column lengths of 24 characters each. Semi-colons cause the output to be printed immediately after the previous output item (numeric items generate one leading and one trailing space).

PRINT provides error processing with the optional "error-cond line-ref" parameter. See Error Conditions for more information.

Technical Considerations

1.) Relevant error conditions are: CONV, EOF, ERROR, EXIT, IOERR, PAGEOFLOW, and SOFLOW.
2.) Standard printer output (PRINT #255) can be redirected using the RUN command. RUN >file-ref creates a new file or overwrites an existing file with printer output. RUN >>file-recreates a new file or appends to an existing display file. RUN >CON: sends printer output to the screen; this option can save paper and speed up debugging and program development.
3.) In unformatted printing, numeric items always generate a leading and a trailing space, both with and without zone printing.
4.) When BELL and NEWPAGE are specified with other data-items and separated by semi-colons, tabbing and column alignment will be off by one column for each reference to BELL or NEWPAGE. This happens because BELL and NEWPAGE occupy positions in the output buffer that is not sent to the screen or printer. The following example prints "HI" in column 28:
00005 PRINT BELL; NEWPAGE; TAB(30); "HI"

This can be avoided by separating BELL, NEWPAGE and TAB(30) by commas, or by placing the BELL and NEWPAGE parameters in PRINT statements that do not include data items, as in the following examples:

00005 PRINT BELL, NEWPAGE, TAB(30); "HI"
00005 PRINT BELL;NEWPAGE; : PRINT TAB(30);"HI"
5.) The PAGEOFLOW error condition can be used for page breaks. After executing a PRINT statement, the system checks to see if the line count is greater than or equal to the value specified for PAGEOFLOW in the OPEN statement (the default is 60). If the test indicates it is time for a page break, control is transferred to the PAGEOFLOW line-ref after the statement has printed. A PRINT #file-num: NEWPAGE statement must be specified to reset the PAGEOFLOW counter to zero; otherwise, the next PRINT would also generate a page overflow condition.
6.) See Functions and Screen I/O for information about HEX$, which can be used in PRINT statements to change to special print modes (condensed, line spacing, etc) and to set the display attributes on the screen.
See BRConfig.sys for information about using PRINTER specifications to create a printer translation interface. PRINT statements using the HEX$ function will probably require some such translation.
7.) Array elements are output in row order (i.e., all elements for a row are processed before moving to the next row). In the program below, the PRINT statement at line 150 inside the loop produces the same output as line 190. This program prints the numbers from 1 to 8 twice:
00100 DATA 1,2,3,4,5,6,7,8
00110 DIM A(4,2)
00120 READ MAT A
00130 FOR I=1 TO 4
00140  FOR J=1 TO 2
00150   PRINT A(I,J),
00160  NEXT J
00170  PRINT
00180 NEXT I
00190 PRINT MAT A
8.) In unformatted PRINT statements, exponential notation occurs with numbers in the following value ranges:
  • Greater than or equal to 1E+10.
  • Less than or equal to -1E+10.
  • Positive, but less than or equal to 1E-10.
  • Negative, but greater than or equal to -1E-10.

See Also