Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DAY 021: LOCATE
#1
Since I'd rather code than write, I decided to present the KEYWORD of the Day, LOCATE in a brief demo. Reading the code window is also an easy option to obtain the various descriptions.

Just press a key during a pause to move on...

Code: (Select All)
' LOCATE Demo
WIDTH 100, 42
_SCREENMOVE 50, 50
'-------------------------------------------------------------------------------------------------------------
PRINT "Locate is used in text screens to locate the cursor by row and column."
PRINT: PRINT "Let's print a message at the 5th row and 2nd column of this window..."
SLEEP
LOCATE 5, 2: PRINT "Hello World!"
SLEEP
PRINT: PRINT "Locate can be used to center text. Let's center our message horizontally..."
SLEEP
msg$ = "Hello World!"
COLOR 14
LOCATE 9, _WIDTH \ 2 - LEN(msg$) \ 2: PRINT msg$
COLOR 7
PRINT: PRINT "CSRLIN denotes the current row and POS(0) for current column...";
SLEEP
LOCATE CSRLIN, POS(0): PRINT " See?..."
SLEEP
PRINT: PRINT "Just be sure you add a semi-colon to the end of your text to stay at the end of the print line."
SLEEP 6: _KEYCLEAR
PRINT: PRINT "If you are already on the row you want, you can also just leave the 1st parameter blank...";
SLEEP
LOCATE , POS(0): PRINT " See?..."
SLEEP
PRINT: PRINT "You can show or hide the cursor, too..."
SLEEP
LOCATE , , 1
PRINT: PRINT "LOCATE , , 1 where our 3rd parameter '1' means let's show the default cursor...";
SLEEP
LOCATE , POS(0), 1
PRINT: PRINT: PRINT "The two last parameters change the cursor shape: cursorStart%, cursorStop%...";
SLEEP 6
PRINT: PRINT: PRINT "The start and end parameters range from 0 to 30. Press to see a medium cursor...";
SLEEP
LOCATE , POS(0), 1, 7, 30
PRINT: PRINT: PRINT "Now press again for a thick cursor...";
SLEEP
LOCATE , POS(0), 1, 0, 30
PRINT: PRINT: PRINT "Note that '7, 7' is the default cursor and 0, 30 is full.";
SLEEP 3
PRINT: PRINT: PRINT "We can hide the cursor with '0' as the 3rd parameter. Press a key to hide it now...";
SLEEP
LOCATE , , 0
SLEEP 3: _KEYCLEAR
LOCATE , , 1
PRINT: PRINT: PRINT "And bring it back again with "; 1; " to its last state LOCATE , , 1, 0, 30...";
SLEEP
LOCATE , , 0
PRINT: PRINT: PRINT "LOCATE also has the ability to print to the last row on a VIEW PRINT restricted screen..."
VIEW PRINT 1 TO 20
SLEEP
LOCATE _HEIGHT, _WIDTH \ 2 - LEN(msg$) \ 2: PRINT msg$;
SLEEP
VIEW PRINT: CLS
PRINT "Finally we need to note some behavior that could screw up your printing.";
SLEEP 4
PRINT: PRINT: PRINT "LOCATE may wrap some text but mostly prints an entire text line to next line...";
LOCATE , , 1, 0, 30
SLEEP
LOCATE , , 0 ' Hide cursor.
PRINT "See? I'm on the next line this time."
SLEEP 6
PRINT: PRINT "This next demo will show what happens when printing an '*' to the last row and column..."
SLEEP
WIDTH 80, 25
CLS
LOCATE 15, 1: PRINT "HEIGHT ="; _HEIGHT, "WIDTH ="; _WIDTH
PRINT: PRINT "Printing an '*' to the right bottom corner with a semi colon works,"
PRINT: PRINT "but look where the next cursor row is."
LOCATE _HEIGHT, _WIDTH
COLOR 14 + 16: PRINT "*";: COLOR 7
y = CSRLIN: x = POS(0)
LOCATE 17: PRINT "Current cursor row is"; y; "instead of"; y + 1; "and the"
PRINT: PRINT "cursor column is"; x; "as expected."
SLEEP
LOCATE y, 1: PRINT "Here's where the next line of text will appear if you don't code a solution."
PRINT: PRINT "See? it's above the asterisk!...";
SLEEP
CLS
PRINT: PRINT "Our final demo will show how to overcome this restriction"
PRINT: PRINT "When trying to fill the screen..."
SLEEP
CLS
a$ = STRING$(_WIDTH, "*")
FOR i = 1 TO _HEIGHT
    PRINT a$;
NEXT
SLEEP
CLS
PRINT "Well that didn't work. The last row was empty because the screen scrolled."
PRINT: PRINT "Hmm, let's use LOCATE to fix that..."
SLEEP
CLS
a$ = STRING$(_WIDTH, "*")
FOR i = 1 TO _HEIGHT
    LOCATE i, 1 ' <---------------------------Fixes scrolling issue.
    PRINT a$;
NEXT
SLEEP
CLS
PRINT "Yep, that worked..."
_DELAY 1
msg$ = "That concludes this portion of our KEYWORD for the Day!"
LOCATE _HEIGHT \ 2, _WIDTH \ 2 - LEN(msg$) \ 2: PRINT msg$
END

Now naturally I did this for SCREEN 0. If anyone wants to elaborate on the use of LOCATE in a graphics environment, feel free.

Pete
Reply


Messages In This Thread
DAY 021: LOCATE - by Pete - 12-02-2022, 04:50 AM
RE: DAY 021: LOCATE - by SMcNeill - 12-02-2022, 05:41 AM
RE: DAY 021: LOCATE - by mnrvovrfc - 12-02-2022, 08:27 AM



Users browsing this thread: 2 Guest(s)