Q(uick)BASIC Statement: LPRINT USING
Quick View
LPRINT USING
A file I/O statement that prints formatted output on the printer LPT1
Worth knowing
Useful and cross-version information about the programming environments of QBasic and QuickBasic.
Syntax
- PRINT [#filenumber%,] USING formatstring$; expressionlist [{; | ,}]
- LPRINT USING formatstring$; expressionlist [{; | ,}]
Description/Parameter(s)
filenumber% | The number of an open sequential file. | |||||||||||||||||||||||||||||||||
formatstring$; | A string expression, specifies the format. Characters in the formatstring$ have the following meaning: | |||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
expressionlist | A list of one or more numeric or string expressions to print, separated by commas, semicolons, spaces, or tabs. | |||||||||||||||||||||||||||||||||
{; | ,} | Determines where the next output begins:
|
Example
a = 123.4567
PRINT USING "###.##"; a
LPRINT USING "+###.####"; a
a$ = "ABCDEFG"
PRINT USING "!"; a$
LPRINT USING "\ \"; a$
See also:
Syntax
- LPRINT [expressionlist][{;|,}]
- LPRINT USING formatstring; expressionlist[{;|,}]
Description/Parameter(s)
- If all arguments are omitted from the LPRINT statement, the printer prints a blank line
- expressionlist is one or more expressions, separated by semicolons
- ";" or "," are optional characters:
- ";" means print immediately after the last value in this LPRINT statement
- "," means print at the start of the next unoccupied print zone
- formatstring in the LPRINT USING statement is a string literal or variable containing literal characters to print and using the same special formatting characters as the ⮜ PRINT USING ⮞ statement.
These statements function in the same way as the PRINT and PRINT USING statements except that output goes to the line printer and the filenumber option is not permitted.
The LPRINT statement assumes an 80-character-wide printer. This width can be changed with a WIDTH LPRINT statement.
Warning
- Since the LPRINT statement uses the LPT1 printer device, you should not use LPRINT in a program that also contains an OPEN LPT1 statement. Using these two statements together produces unpredictable results.
Differences from BASICA
- If you do LPRINT CHR$(13), BASIC actually outputs LPRINT CHR$(13) and LPRINT CHR$(10). This feature was created to provide compatibility between Microsoft BASIC and IBM BASICA.
Example
See the ⮜ LPOS function programming example ⮞, which uses the LPRINT command.
See also:
Syntax
- LPRINT USING formatstring$; expressionlist [{;|,}]
Description/Parameter(s)
formatstring$ | Specifies the format, using the same formatting characters as the ⮜ PRINT USING ⮞ statement. |
expressionlist | The values that are printed on printer LPT1:. |
{;|,} | Determines the location on the page of the first value printed by the next statement to use LPT1 (such as the next LPRINT statement or a PRINT # or WRITE # directing data to LPT1).
|
- The printer output from an LPRINT USING statement will be the same as the screen output from a PRINT USING statement, if both statements have the same values for formatstring$, expressionlist, and output line width.
Important
- Because the LPRINT USING statement uses the LPT1 printer device, you should not use LPRINT USING in a program that also contains an OPEN "LPT1" statement. Using these two statements together produces unpredictable results.
Usage Notes
- This statement functions in the same way as the PRINT USING statement except that output goes to the printer.
- The printer output from an LPRINT USING statement will be the same as the screen output from a PRINT USING statement, if both statements have the same values for formatstring$, expressionlist, and output-line width.
- The LPRINT USING statement assumes an 80-character-wide printer. This width can be changed with a WIDTH statement.
- If you use LPRINT USING with no arguments, a blank line is printed.
Example
This example uses the LPRINT USING statement to print a receipt on the printer.
Note: To run this program, you must have a printer connected to LPT1.
CLS 'Clear screen.
Total = 0
LPRINT "Your receipt:"
LPRINT
DO
INPUT "Enter quantity (0 to end): ", Quantity
IF Quantity = 0 THEN EXIT DO
INPUT "Item name: ", Item$
INPUT "Amount: ", Amount
PRINT
'Calculate subtotal.
Amount = Amount * Quantity
Total = Total + Amount
'Print line of receipt.
LPRINT USING "### "; Quantity;
LPRINT USING "\ \"; Item$;
LPRINT USING "$$######,.##"; Amount
LOOP
'Finish receipt.
LPRINT
LPRINT TAB(12); "Total amount paid: ";
LPRINT USING "$$#######,.##"; Total
Sample Output:
Enter quantity (0 to end): 1 Item name: Used car Amount: 3999 Enter quantity (0 to end): 10 Item name: Gallons gas Amount: .98 Enter quantity (0 to end): 0 Output on line printer Your receipt: 1 Used car $3,999.00 10 Gallons gas $9.80 Total amount paid: $4,008.80