Qbasic Tutorial for beginners and children (Under Construction)


The LOCATE statement

The LOCATE statement is used to move the cursor on the screen.

The syntax is:

LOCATE row, column

Example:

LOCATE 20, 30

PRINT "20th row, 30th Column"

By default there are 25 rows and 80 columns in BASIC, but this can be modified depending upon the screen resolution you are working.

The example above displays the text "20th row, 30th column" at the 20th row and 30th column of the basic screen.

 

Using the locate statement in BASIC may result into "weird behaviour" from your program.

 

Try the following example

 

CLS

LOCATE 1, 20

PRINT "Can you see me?"

LOCATE 25, 20

PRINT "Where are you?"

SLEEP

 

In the example above the sentence "Can you see me?" disappeared from the screen. So what happened? 

The problem lies with with the 4th and 5th lines of your code. When you use the PRINT statement without putting a semicolon or a comma sign at the end of the line, BASIC sends a line feed bringing the cursor to the next line. Since we were at the 25th row, the screen scrolls one line down and your original first line gets "on top of the screen".

To solve this problem put a semicolon at the end of the PRINT statement.

CLS

LOCATE 1, 20

PRINT "Can you see me?"

LOCATE 25, 20

PRINT "Where are you?";

SLEEP

 

[ Previous Index Next ]


pages viewed since January  19 2002