Q(uick)BASIC Function: POS

Quick View

POS

A device I/O function that returns the current horizontal position of the cursor

Worth knowing

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

Syntax
  • LOCATE [row%] [,[column%] [,[cursor%] [,start% [,stop%]]]]
  • CSRLIN
  • POS(expression)
Description/Parameter(s)
row% and column% The number of the row and column to which the cursor moves.
cursor% Specifies whether the cursor is visible: 0 = invisible, 1 = visible
start% and stop% Integer expressions in the range 0 through 31 that specify the first and last cursor scan lines. You can change the cursor size by changing the cursor scan lines.
expression Any expression.
Example
CLS LOCATE 5, 5 MyRow% = CSRLIN MyCol% = POS(0) PRINT "Position 1 (Press any key)" DO LOOP WHILE INKEY$ = "" LOCATE (MyRow% + 2), (MyCol% + 2) PRINT "Position 2"
Syntax
  • POS(0)
Description/Parameter(s)

The leftmost cursor position is numbered 1. To return the current vertical-line position of the cursor, use the CSRLIN function.

Example

This example uses POS to start a new line after every 40 characters.

CLS ' Clear screen PRINT "This program starts a new line after every 40" PRINT "characters you type. Press <CTRL-C> to end." PRINT DO DO WHILE POS(0) < 41 'Stay on same line until 40 characters DO 'printed. Char$ = INKEY$ LOOP WHILE Char$ = "" 'If input is key combination CTRL-C then end; otherwise, 'print the character. IF ASC(Char$) = 3 THEN END ELSE PRINT Char$; LOOP PRINT 'Print a new line. LOOP

See also:

Syntax
  • POS(numeric-expression)
Description/Parameter(s)
(numeric-expression) Can be any numeric expression. While it passes no information, it is required to maintain consistent BASIC function syntax.
  • If the screen cursor is in the leftmost column, this function returns a value of 1.
  • To return the current vertical (screen row) position of the cursor, use the CSRLIN function.
Example

This example uses the POS function to start a new line after every 40 characters.

CLS 'Clear screen. PRINT "This program starts a new line after every 40" PRINT "characters you type. Press <CTRL-C> to end." PRINT DO DO WHILE POS(0) < 41 'Stay on same line until 40 characters DO 'printed. Char$ = INKEY$ LOOP WHILE Char$ = "" 'If input is key combination CTRL-C then end; otherwise, 'print the character. IF ASC(Char$) = 3 THEN END ELSE PRINT Char$; LOOP PRINT 'Print a new line. LOOP