Q(uick)BASIC Statement: LPRINT

Quick View

LPRINT

A file I/O statement that prints data on the printer LPT1

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • PRINT [#filenumber%,] [expressionlist] [{; | ,}]
  • LPRINT [expressionlist] [{; | ,}]
Description/Parameter(s)
filenumber% The number of an open file. If you don't specify a file number, PRINT writes to the screen.
expressionlist A list of one or more numeric or string expressions to print.
{; | ,} Determines where the next output begins:
  • ; means print immediately after the last value.
  • , means print at the start of the next print zone.
  •   Print zones are 14 characters wide.
Example
OPEN "TEST.DAT" FOR OUTPUT AS #1 PRINT #1, USING "##.### "; 12.12345 CLOSE OPEN "TEST.DAT" FOR INPUT AS #1 INPUT #1, a$ PRINT a$ LPRINT "This is a line"; 1 LPRINT "This is a line", LPRINT 2
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.

Syntax
  • LPRINT [expressionlist] [{;|,}]
Description/Parameter(s)

Important

  • Because 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.

Usage Notes

  • This statement functions in the same way as the PRINT statement except that output goes to the printer.
  • The printer output from the LPRINT statement will be the same as the screen output from a PRINT statement, if both statements have the same expressionlist values and output-line width.
  • The LPRINT statement assumes an 80-character-wide printer. This width can be changed with a WIDTH statement.
  • If you use LPRINT with no arguments, a blank line is printed.
  • An LPRINT CHR$(13) statement outputs both CHR$(13) and CHR$(10), providing compatibility with BASICA.
Example

This example uses the LPRINT statement to print team and player names on a line printer. The LPOS function is used to determine the position of the print head and avoid printing past the end of the line.
Note: To run this program, you must have a printer connected to LPT1.

CLS 'Clear screen. LPRINT "Team Members"; TAB(76); "TEAM" LPRINT INPUT "How many teams"; TEAMS INPUT "How many players per team"; PPT PRINT FOR T = 1 TO TEAMS INPUT "Team name: ", TEAM$ FOR P = 1 TO PPT INPUT " Enter player name: ", PLAYER$ LPRINT PLAYER$; IF P < PPT THEN IF LPOS(0) > 55 THEN 'Print a new line if print 'head past column 55. LPRINT : LPRINT " "; ELSE LPRINT ", "; 'Otherwise, print a comma. END IF END IF NEXT P LPRINT STRING$(80 - LPOS(0) - LEN(TEAM$), "."); TEAM$ NEXT T