The PRINT statement sends data to the display terminal or to another specified print unit.
Format
PRINT[ON unit#] print-expr |
Parameter(s)
ON unit# |
Specifies that data should be output to a Spooler print unit unit#. unit# may be any integer in the range 0 to 254, with 0 as the default. Print unit 0 is interpreted as either the display terminal or the printer, depending on previous use of the PRINTER statement. When the program is terminated or when a PRINTER CLOSE statement is used, all print units are output to the printer. This option is used when several different reports are generated by the program simultaneously. |
print-expr |
Print expression optionally combined with commas and colons to designate the format of the output (as described below). If print-expr is omitted, a blank line is output. |
Description
The PRINTER statement determines the output device to which data will be written by the PRINT statement. See PRINTER Statement for more information. There is also a CRT (or DISPLAY) statement available in mvBASIC, which is identical to the PRINT statement except that it always prints its output to the screen, regardless of whether a PRINTER ON statement had been issued. In addition, there is also a SEND statement which may be used to send data to the screen of an attached line.
Formatted Output
The FMT function may be used to provide complex formatting specifications for output. See FMT Function for more information. Within the PRINT statement, however, commas and colons may be used to specify tab stops and suppress linefeeds.
Expressions separated by commas (,) are printed at preset tab positions. Multiple commas may be used together to cause multiple tabulations between expressions. However, tab positions cannot be specified without being surrounded by expressions.
Colons (:) encountered between expressions are interpreted normally as the string concatenation operator. If the last character of the PRINT statement is a colon, however, the linefeed and carriage return which usually follow the print statement are suppressed. This is especially useful when an INPUT statement is to follow, or in formatted screen programs.
The @ function may be used with the PRINT statement to send the cursor to a specified location on the screen. Also, as shown in the second example, the @ function may be used to alter the attributes applied to text. For additional information regarding the @ function, refer to Overview of mvBASIC Statements and Functions.
Example
In this application, the full contents of a dimensional array are printed via a FOR...NEXT loop. Only one element is printed at a time, however; hence, to imitate the actual structure of the array, tab stops are generated with commas and new lines are suppressed with colons. Before a new row is begun, the carriage return is generated by a null PRINT statement.
FOR I=1 TO 4 FOR J=1 TO 3 PRINT CUSTOMER(I,J), " " : NEXT J NEXT I |
If the array CUSTOMER contains the name, telephone number, and marital status of each customer, the output might be:
FRED HENKEL |
555-1234 |
SINGLE |
ARCHIE ANDREWS |
555-4321 |
MARRIED |
MARGARET WOOD |
867-5309 |
SEPARATED |
LUCY RICARDO |
338-6887 |
MARRIED |
In the next example, the @ function is used with the PRINT statement to print an error in blinking text onto the bottom of the screen. It also clears the rest of the line, in case there had already been text on that line. Note that the cursor remains at the bottom of the screen after the error message is printed.
PRINT "ENTER YOUR SOCIAL SECURITY NUMBER : " PROMPT "" INPUT ANSWER,11,"*#"_ IF ANSWER MATCHES "3N-2N-4N" THEN GOSUB SOCSEC END ELSE PRINT @(0,23) : @(-5) : ANSWER : " : DOES NOT MATCH SS #" : PRINT @(-6) : @(-4) : END . . . |
See Also