home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
CP/M
/
CPM_CDROM.iso
/
cpm
/
basic
/
mbaspos.txt
< prev
next >
Wrap
Text File
|
1994-07-13
|
3KB
|
66 lines
CURSOR POSITIONING CAN BE FUN IF YOU KNOW THE RIGHT PROCEDURES
by Editor, KUGOR BYTES, July 1987
(Using functions and procedures in BASIC to position the cursor)
Is there any way to position the cursor on the screen with single
command in MBasic or SBasic? Both of these languages, which came
bundled with the Kaypro, are very useful, but can become awful
tiring having to issue dozens of PRINT commands -- unless you
don't mind everything printing at the upper left corner...
There certainly is a time saving method to get that cursor (or
output) smack dab where you want it. MBasic employs what are
known as user defined functions. Early on the program, define
the function. The command is DEF (for define, followed by a
space and FN (for function), then (no space) an arbitrary
variable to identify the particular function, and a $ if you are
defining a string. This is followed by the variables, in
parentheses, which will change throughout the program, an equals
sign, and the calculations for the function itself.
DEF FNfunction
name(variables)=function
To position the cursor in MBasic, use this simple formula:
CHR$(27)+"="+CHR$(Y+32)+CHR$(X+32) exactly as shown. The Y
stands for line number and X for row number. Thus, the user
defined function will be initialized as:
DEF FNC$(Y,X)=CHR$(27)+"="+CHR$(Y+32)+CHR$(X+32)
Now anytime you want to position the cursor or output at a
specific point on the screen, let's say 10 lines down and 5
columns in, use FNC$(10,5).
Try this example --
PRINT FNC$(11,31);"This is the middle"
That will place the string in quotation marks right in the center
of the screen. Once defined at the beginning of a program, user
defined functions can be called again and again.
In S-Basic, it is even easier. S-Basic employs procedures, which
operate much the same way as MBasic user defined functions,
except they allow you to call with mnemonics. I like to use the
following:
PROCEDURE AT (Y,X=INTEGER)
PRINT CHR(27)+"="+CHR(Y+32)+CHR(X+32)END
In this simple statement, the keyword PROCEDURE tells S-Basic
that you are defining a procedure. What follows is your name for
the procedure; I've used AT, as you'll soon understand. Then the
variables Y,X are established. After that we enter the formula
-- same as in MBasic. S-Basic doesn't need the $ string
appendage.
Now, to position something within a program, I can write:
AT 11,31
PRINT "This is the middle"
Get the mnemonic subtleties? It's really quite easy and once you
get the hang of it, you'll be designing your programs as well as
writing them!