Print Using

From BR Wiki
Jump to navigation Jump to search

The Print Using (PR U) statement sends formatted output to the screen, a window, a printer, a display file, a communications file, or another device assigned by an OPEN statement.

Comments and Examples

PRINT USING is usually used for printing reports. It is probably the most commonly used variation of the PRINT statement, especially with printers. The USING clause usually indicates the line number of a FORM statement which specifies where information should appear in the next line or lines of output.
Lines 200 to 230 provide an example of Print Using formatted output:

00200 LET BAL = 1234.56
00210 LET COMPANY$ = "XYZ Company"
00220 PRINT #255,USING 230: BAL, COMPANY$
00230 FORM N 7.2," owed by ",C 25

The PRINT statement in line 220 in the above example uses the FORM statement in line 230. In line 230, N 7.2 specifies that a numeric value (BAL from line 220) is to be printed in the first seven output columns with a decimal point and two decimal digits. The material inside the quotation marks in line 230 is output next; this occupies columns 8 to 16. C 25 indicates that the next 25 columns (17 to 43) are to contain the value of the string variable COMPANY$. Thus, the output from this statement is:

1234.56 owed by XYZ Company

Another example:

01000 print #255,using dateform: " ",Protect$,Q$,C1,E$
01010 print #255,using payamountform: B(6)
01020 dateform: form C 1,Skip 1,pos 10, c 120,skip 0, Pos 82,C 8,X 5,Pic(Zzzzz#),x 12,c 4,Skip 2
01030 payamountform: form  Pos 92,Pic(***,**#.##),Skip 1


PRINT [{#<file number>,|#<window number>,}] USING {<line ref>|<string expression>} : [{MAT <array name>|}[,...]] [<error condition> <line ref>][,...]


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


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 "USING" keyword specifies the "line-ref" of a FORM statement or a "string-expr" containing a FORM statement. USING is responsible for the format of the output.

The optional "data-item" and "MAT array name" parameters identify the items to be output. Multiple specifications must be separated by commas.

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-ref creates 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.) The position after the USING keyword may contain a string expression (constant or variable) which must begin with the keyword "FORM " followed by a list of format specifications. This method is relatively slow because the string must be compiled on each execution.
4.) The PAGEOFLOW error condition can be used for page breaks. After executing a PRINT statement, Business Rules 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.
5.) 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.
6.) Array elements are output in row order (i.e., all elements for a row are processed before moving to the next row).
7.) When OPTION INVP is in effect, the normal printing of commas and periods is interchanged in PIC, N, NZ, G and GZ format specifications to produce European- style numbers.