LOCATE - QB64 Wiki


From QB64 Wiki

Jump to: navigation, search

The LOCATE statement locates the screen text row and column positions for a PRINT or INPUT procedure.


LOCATE [row%][, column%] [, cursor%][, cursor_start%, cursor_stop%]


  • optional text row INTEGER values are from 1 to the 25, 43 or 50 in SCREEN 0 and 25 in most other graphic screen modes, except screens 11 and 12 which can have 30 or 60.
  • optional column INTEGER values are from 1 to 40 or 80 in SCREEN 0 and 80 in all other legacy screen modes.
  • optional cursor value can be 0 to turn the cursor off or 1 to turn it on when using the INPUT$ or INKEY$ key entry functions only.
  • optional cursorstart and cursorstop values define the shape of the cursor by setting the start and stop scanline (0-8 pixels) for the cursor character.


  • WIDTH statement can be used to determine the text width and height in SCREEN 0 and height of 30 or 60 in SCREEN 11 or 12.
  • In _NEWIMAGE graphic screen text rows are calculated as _HEIGHT \ 16 except when a _FONT is used. Use _FONTHEIGHT to calculate font rows.
  • _NEWIMAGE graphic screen text columns are calculated as _WIDTH \ 8 except when a _FONT is used. Use _PRINTWIDTH to measure a line of font text.
  • The text row position is not required if the PRINT is going to be on the next row. The comma and a column value are required to set the column.
  • If only the row parameter is given, then the column position remains the same. Neither row or column parameter can be 0!
  • When PRINTing on the bottom 2 rows, use a semicolon after the PRINT expression to avoid a screen roll.
  • If the cursor start line is given, the cursor stop line must also be given. A wider range between them produces a taller cursor.

Example: Moving the cursor around (now you can finally create a Commodore 64 emulator!). Default SCREEN 0 ONLY!

crx = 10 cry = 10 DO LOCATE cry, crx, 1, 0, 8 a$ = INKEY$ SELECT CASE a$ CASE CHR$(0) + "H": IF cry > 1 THEN cry = cry - 1 'up CASE CHR$(0) + "P": IF cry < 25 THEN cry = cry + 1 'down CASE CHR$(0) + "K": IF crx > 1 THEN crx = crx - 1 'left CASE CHR$(0) + "M": IF crx < 80 THEN crx = crx + 1 'right CASE CHR$(27): END END SELECT LOOP

Explanation: The CHR$(0) + "H", "P", "K", "M" represents the cursor arrow keys. start = 0, stop = 8 is the tallest cursor, experiment with the start and stop values for different effects (start = 8, stop = 8 is the default producing a _ cursor).

See also:

Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page
  • Page
  • Discussion
  • View source
  • History
Personal tools
  • Log in
  • What links here
  • Related changes
  • Special pages
  • Printable version