There are two standard output devices available to an mvBASIC program:
Terminal screen
Printer
The CRT and DISPLAY statements send output only to the terminal screen, and the PRINT statement sends its output either to the terminal screen or to the printer, depending on which has been selected as the output device. The syntax of all three statements is identical, except that the PRINT statement accepts the ON keyword for multiple print units.
In a broader sense, file items and attached tape devices or floppy disk devices can also be considered output devices. See Reading and Updating File Items and Reading and Writing Tapes or Floppy Disks later in this section for information on file I/O, tape I/O, and floppy disk I/O.
The PRINT statement by default sends output to the screen. There are two ways, however, to force the PRINT statement to send output to the printer: by the P option to the RUN command, or by the PRINTER ON statement. The PRINTER ON statement signifies that all subsequent PRINT statements will send output to a Spooler print unit. At the end of the program, the print unit will be sent to the Spooler.
The PRINTER OFF statement returns to the default condition: all PRINT statements after a PRINTER OFF statement will send output to the terminal screen again. To print output before the end of the program, the PRINTER CLOSE statement is available to send everything in the print unit directly to the Spooler.
When output is being sent to a printer, the ON keyword to PRINT becomes significant. Generally, all printer output is sent to print unit 0. However, if several reports are being generated simultaneously, the ON keyword can be used to place output in several different print units (ranging from 0 to 599).
For example, suppose a program generates two reports, one displaying the names of all customers who are two months late on their bills, and the other displaying the names of all customers who have birthdays approaching. The program goes through each customer’s record in sequence. If bills have not been paid, the customer’s name and address are printed from print unit 0, and the customer is billed. If the customer has a birthday coming up, the name and address are printed from print unit 1, and the customer is sent a birthday card. At the end of the program, two complete (and hopefully distinctive) lists are printed out.
Normally output will be printed at the current position, and will force a carriage return and linefeed at the end of output. The print expression, however, may include features to tabulate output, to suppress the carriage return and linefeed, and (in the case of screen output) to place output at any coordinate, clear the screen, clear the line, or access any of several terminal capabilities.
In addition, format can be masked directly in an output expression. Format masking is a mechanism in mvBASIC by which data can be converted into a readable format without changing the data itself.
A comma (,) in the print expression will force a tab to be printed at that position. A trailing colon (:) specifies that the automatic carriage return and linefeed will be suppressed in output.
The @ function provides direct control of a terminal screen. When the @ function is used in a print expression, it generates a command sequence that is sent to the terminal screen, and the screen responds accordingly. In particular, the @ function can be used to move the cursor to any coordinate position on the screen. It can also be used to clear the screen, to clear to the end of the line, or to place the text in blinking mode. A full list of the features for the @ function is included in the reference page for @.
Using the @ function, a formatted screen can be generated. Programs can use the @ function to clear the screen and show a menu by sending menu options to different coordinates on the screen. The programmer might choose to turn the echo feature off to prevent user input from appearing on the screen.
For formatted screens, the INPUT @ statement can take input from any coordinate on the screen. In addition, the INPUT @ statement performs format masking directly on the input. See Terminal Input later in this section for more information on INPUT @.
Example
To print a menu on the screen, the source code might read:
PRINT @(-1) : PRINT @(8,3) : "CHOOSE ONE: " : PRINT @(16,6) : @(-13) : "E" : @(-14) : "DIT AN ENTRY" : PRINT @(16,8) : @(-13) : "N" : @(-14) : "EW ENTRY" : PRINT @(16,10) : @(-13) : "D" : @(-14) : "ELETE AN ENTRY" : PRINT @(16,12) : @(-13) : "Q " : @(-14) : "UIT" : ECHO OFF INPUT @(1,23) : ANSWER,1 |
The code in the preceding example does the following:
The first line of code clears the screen.
The second line prints CHOOSE ONE at column 8, row 3.
The third through sixth lines print the menu options at specific coordinates, with the first character in reverse video mode. Thus, the first character stands out on the screen.
The seventh line turns off the echo.
The eighth line places the cursor at the bottom of the screen and accepts a single character as a response.
Numbers are stored in internal format. Internal format is a representation of data which makes calculation easier but is more difficult to read. Format masks convert numbers into a format that is easier to read. In addition, the ICONV function converts string data into internal format, and the OCONV function converts strings back into external format.
For example, if the dollar amount $14,912.15 were stored with the dollar sign and comma, then any calculations on that number would be impossible—dollar signs and commas are not permitted in numeric values. Also, if interest is being calculated on this dollar amount, it would be much more accurate if more than two decimal places were being kept.
Suppose that the given dollar amount represents the balance of a bank account. The bank keeps this figure to 5 digits of precision, to ensure that any calculations are accurate—suppose the actual figure stored is 1491214987. When this figure needs to be printed in a monthly statement, the data needs to be converted into a readable form. The program which generates the monthly statements will therefore print the data with a format mask, which will descale the number, round it to 2 decimal places, enter a comma where necessary, and precede it with a dollar sign. If the variable BALANCE contains 1491214987, and the program contains the lines:
PRECISION 4 . . . PRINT BALANCE "29,$" the output will be: $14,912.15 |
A data mask can be implemented in two ways: either by using the FMT keyword, or by simply following data with the mask expression (as shown in the example). In the source code, the 2 signifies that the output should be rounded to two decimal places. The 9 is a descaling code, which determines where to place the decimal point—in this case, with a precision of 4 and a descaling code of 9, the decimal point is placed (9-4)=5 digits from the right. The, signifies to enter a comma every thousands place, and the $ says to precede the expression with a dollar sign. There are many other codes available for masking data. For a full list and explanation of these codes, see the reference page for FMT in Statement and Function Reference.
The HEADING statement can be used to specify a heading to be printed at the top of each page. It also has the facility to set up page parameters for use by FOOTING and PAGE.
If the output is being sent to the screen, then output will stop after each page of text once a HEADING statement is used. If a FOOTING statement is specified, a footing will be supplied at the end of the page, and the program will wait for a carriage return before continuing with output.
The PAGE statement can be used to force a new page at any point in the program, as long as a HEADING has been specified.
Note that HEADING, FOOTING, and PAGE will only affect the same output device that PRINT does. If multiple print units are being printed together, HEADING, FOOTING, and PAGE will affect print unit 0 (the default).
The PRINTERR statement allows mvBASIC programs to produce output messages using the Error Message Processor and the ERRMSG file.
Before the introduction of the PRINTERR statement, the Error Message Processor was only available through the use of the STOP and ABORT statements, both of which terminated the program.
See Also
Overview of mvBASIC Statements and Functions
Reading and Updating File Items
Reading and Writing Tapes or Floppy Disks