Q(uick)BASIC Function: LPOS

Quick View

LPOS

A device I/O function that returns the current position of the line printer's print head within the printer buffer

Worth knowing

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

Syntax
  • LPOS(n%)
Description/Parameter(s)

LPOS returns the number of characters sent to a printer since the last carriage return was sent.

n% Indicates one of the printer ports:
0 = LPT1, 1 = LPT1, 2 = LPT2, 3 = LPT3
Example

This example requires a printer.

LPRINT FOR i% = 1 TO 20 LPRINT i%; IF LPOS(1) >= 10 THEN LPRINT 'Begin a new line. NEXT i%
Syntax
  • LPOS(n)
Description/Parameter(s)
The argument n is the index of the printer being tested:
LPT1: would be tested with LPOS(1) or LPOS(0)
LPT2: would be tested with LPOS(2)
LPT3: would be tested with LPOS(3)
The LPOS function does not necessarily give the physical position of the print head because it does not expand tab characters. In addition, some printers may buffer characters.
Example

This example prompts the user for team names and the names of players on each team. It then prints the players and their teams on the printer.

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
Syntax
  • LPOS(n%)
Description/Parameter(s)

LPOS returns the number of characters sent to the printer since the last carriage return was sent.

n% An integer expression with a value between 0 and 3 that indicates one of the printers:
0 = LPT1, 1 = LPT1, 2 = LPT2, 3 = LPT3
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