Q(uick)BASIC Statement: LOCATE

Quick View

LOCATE

A device I/O statement that moves the cursor to the specified position

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
  • LOCATE [row][,[column][,[cursor][,[start,stop]]]]
Description/Parameter(s)
Argument Description
row The number of a row on the screen; row is a numeric expression returning an integer. If row is not specified, then the line (row) does not change.
column The number of a column on the screen; column is a numeric expression returning an integer. If column is not specified, then the column location does not change.
cursor A Boolean value indicating whether the cursor is visible or not. A value of 0 (zero) indicates cursor off; a value of 1 indicates cursor on.
start The starting scan line of cursor on the screen. It must be a numeric expression returning an integer.
stop The ending scan line of cursor on the screen. It must be a numeric expression returning an integer.

You may omit any argument from the statement. When you omit the row or column, LOCATE leaves the cursor at the row or column where it was moved by a previous LOCATE or a previous input or output statement, whichever occurred most recently. When you omit other arguments, QuickBASIC assumes the previous value for the argument.

Note that the start and stop lines are the CRT scan lines that specify which pixels on the screen are lit. A wider range between the start and stop lines produces a taller cursor, such as one that occupies an entire character block. When start is less than stop, LOCATE produces a two-part cursor. If the start line is given, stop must also be specified.

The last line on the screen is reserved for the soft-key display and is not accessible to the cursor unless the soft-key display is off (KEY OFF) and LOCATE is used with PRINT to write on the line.

Examples

Here is an example that shows the effects on the cursor of different LOCATE statements:

CLS 'Clear screen LOCATE 5, 5 'Moves cursor to row 5, column 5 PRINT "C" DO LOOP WHILE INKEY$ = "" 'Press any key to continue LOCATE 1,1 'Moves cursor to upper-left corner of the screen. PRINT "C" DO LOOP WHILE INKEY$ = "" 'Press any key to continue LOCATE,,1 'Makes the cursor visible; position remains 'unchanged. PRINT "C" DO LOOP WHILE INKEY$ = "" 'Press any key to continue LOCATE,,,7 'Position and cursor visibility remain unchanged; 'sets the cursor to display at the bottom of 'the character box starting and ending on 'scan line 7. PRINT "C" DO LOOP WHILE INKEY$ = "" 'Press any key to continue LOCATE 5,1,1,0,7 'Moves the cursor to line 5, column 1; 'turns cursor on; cursor covers entire 'character cell starting at scan line '0 and ending on scan line 7. PRINT "C" DO LOOP WHILE INKEY$ = "" 'Press any key to continue

Here is part of a program that prints a menu on the screen, then waits for input in the allowable range (1-4). If a number outside that range is entered, the program continues to prompt for a selection.
Note: This program is incomplete. Do not try to run it in its current form.

CONST FALSE=0, TRUE=NOT FALSE DO CLS PRINT "MAIN MENU" : PRINT PRINT "1) Add Records" PRINT "2) Display/Update/Delete a Record" PRINT "3) Print Out List of People Staying at Hotel" PRINT "4) End Program" ' Change cursor to a block. LOCATE ,,1,1,12 LOCATE 12,1 PRINT "What is your selection?"; DO CH$ = INPUT$(1) LOOP WHILE (CH$ < "1" OR CH$ > "4") PRINT CH$ ' Call the appropriate subprogram. SELECT CASE VAL(CH$) CASE 1 CALL Add CASE 2 CALL Search CASE 3 CALL Hotel CASE 4 CALL Quit END SELECT LOOP WHILE NOT ENDPROG . . . END
Syntax
  • LOCATE [row%] [,[column%] [,[cursor%] [,start% [,stop%]]]]
Description/Parameter(s)
  • The argument row% is the number of a row on the screen; row% is a numeric expression that returns an integer. If row% is not specified, the row location of the cursor does not change.
  • The column% is the number of a column on the screen; column% is a numeric expression that returns an integer. If column% is not specified, the column location of the cursor does not change.
  • The cursor% is a Boolean value indicating whether the cursor is visible or not. A value of 0 indicates cursor off; a value of 1 indicates cursor on.
  • The start% is the starting scan line of the cursor on the screen. It must be a numeric expression that returns an integer between 0 and 31, inclusive.
  • The stop% is the ending scan line of the cursor on the screen. It must be a numeric expression that returns an integer between 0 and 31, inclusive.

Usage Notes

  • You can omit any argument from the statement except that if stop% is specified, start% also must be specified. When you omit row% or column%, LOCATE leaves the cursor at the row or column where it was moved by the most recently executed input or output statement (such as LOCATE, PRINT, or INPUT). When you omit other arguments, BASIC assumes the previous value for the argument. The start and stop lines are the CRT scan lines that specify which pixels on the screen are lit:
    • A wider range between the start and stop lines produces a taller cursor, such as one that occupies an entire character block.
    • In OS/2 real mode and under DOS, LOCATE assumes there are eight lines (numbered 0 to 7) in the cursor. In OS/2 protected mode there are 16 lines (numbered 0 to 15).
  • When start% is greater than stop%, LOCATE produces a two-part cursor:
    • If the start line is given, but the stop line is omitted, stop% assumes the same value as start%.
    • A value of 8 for both start% and stop% produces the underline cursor.
    • The maximum cursor size is determined by the character block size of the screen mode in use.
    • Setting start% greater than stop% displays a full-height cursor on VGA-equipped systems.
  • For screen mode information, see SCREEN Statement .
Examples

This example shows the effect of different LOCATE statements on the cursor.

CLS 'Clear screen. LOCATE 5, 5 'Moves cursor to row 5, column 5. PRINT "C" DO LOOP WHILE INKEY$ = "" 'Press any key to continue. LOCATE 1, 1 'Moves cursor to upper-left corner of the screen. PRINT "C" DO LOOP WHILE INKEY$ = "" 'Press any key to continue. LOCATE , , 1 'Makes the cursor visible; position remains 'unchanged. PRINT "C" DO LOOP WHILE INKEY$ = "" 'Press any key to continue. LOCATE , , , 7 'Position and cursor visibility remain unchanged; 'sets the cursor to display at the bottom of 'the character box starting and ending on 'scan line 7. PRINT "C" DO LOOP WHILE INKEY$ = "" 'Press any key to continue. LOCATE 5, 1, 1, 0, 7 'Moves the cursor to line 5, column 1; 'turns cursor on; cursor covers entire 'character cell starting at scan line '0 and ending on scan line 7. PRINT "C" DO LOOP WHILE INKEY$ = "" 'Press any key to continue. END

This example prints a menu on the screen, then waits for input in the allowable range (1-4). If a number outside that range is entered, the program continues to prompt for a selection.
Note: This program is incomplete. Do not try to run it in its current form.

CONST FALSE = 0, TRUE = NOT FALSE DO CLS PRINT "MAIN MENU": PRINT PRINT "1) Add Records" PRINT "2) Display/Update/Delete a Record" PRINT "3) Print Out List of People Staying at Hotel" PRINT "4) End Program" 'Change cursor to a block. LOCATE , , 1, 1, 12 LOCATE 12, 1 PRINT "What is your selection?"; DO CH$ = INPUT$(1) LOOP WHILE (CH$ < "1" OR CH$ > "4") PRINT CH$ ' Call the appropriate subprogram. SELECT CASE VAL(CH$) CASE 1 CALL Add CASE 2 CALL Search CASE 3 CALL Hotel CASE 4 CALL Quit END SELECT LOOP WHILE NOT ENDPROG ' . ' . ' . END