home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
TCE Demo 2
/
TCE_DEMO_CD2.iso
/
demo_cd_.2
/
mags
/
stosser
/
stoser01.arj
/
stoser01.msa
/
A
/
A10.DOC
< prev
next >
Wrap
Text File
|
1987-04-22
|
9KB
|
208 lines
UNDERSTANDING STOS BASIC
¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
By Dion Guy
Part 1 of a complete guide to variables
This article has been copied in it's entirety from STOS MAGAZINE
thank's to the kind permision of it's author DION GUY who retains
the copyright to the said article
**************
Variables are simply thing's which hold information inside the
computer, There are mainly three types of variables, an integer
variable, a string variable, and a real number variable , The
first the integer variable can only hold whole number's, The
second a string variable can hold letters and numbers, Lastly a
real number variable can hold any number whole or otherwise-eg
1.32.
Variable names can take the form of any word or phrase you like
but to a length of 31 character's. The only condition is that
within the 31 character's there must not be any of the following
STOS basic keyword's:
TO,STEP,THEN,ELSE,XOR,OR,AND,GOTO,GOSUB,MOD,and AS.
For example the following names are illegal :
HANDLE, SCORE, TOP, MAST,-hANDle, scORe, TOp, mASt.
However the following names are perfectly acceptable:
TEXT, LIVES, BONUS, HELP.
To specify whether the variable name applies to a integer ,real
number or string variable you have to apply the following .If it
is a integer variable you can just use the name on it's own. eg
TEST, SET, A or something like that .If it is a real number
variable then you have to add a # to the name so the above names
would become -TEST# , SET#, A#. For a string variable you have to
add a $ so the above would be - TEST$, SET$, A$.
The kind of information you can store in these variable's is as
follows :
integer variable - any whole number from -2147483648 to
+2147483648
real number variable- any number from 1E-14 to 1E+15(STOS V2.4
or V2.5 only).
String variables can hold any text - numbers,letters etc - up to
a maximum of 65500 characters.
So- let SET=15,let TEST#=32.56 and let A$="hello!" are all legal
uses of variables.Different kinds of variables can be used and
manipulated in different ways. There are quite a lot of ways
to manipulate string variables,but on the other hand there are a
lot of ways to use integer and real number variables.
Following is part 1 of an A-Z list of things to do with
variables.Some are commands which directly affect variables,others
are just handy things I use in conjunction with variables.When a
command has brackets it will have something inside them - either
var or num var.Var means use of a string variable, num var means
use an integer or real number variable.
ABS(num var)
ABS stands for ABSolute and will return the absolute value of a
number, regardless of the sign. Eg - print abs(-73) - will display
73.
ASC(var)
ASC stands for ASCII (American Standard Code for Information
Interchange). This is used to assess the ASCII value of a letter.
It is often used in conjunction with inkey$ to read keyboard
input.The computer holds 255 ASCII codes in memory.Eg - print
asc(A) - displays 65 (the ASCII code for A).
BIN$(num var)
Used to convert numbers into binary strings, BIN$ is one of
those functions I rarely use! Eg - print bin$(63) - will display
%111111 which is the binary value for 63.
CHR$(num var)
CHR$ is used to display or create the character with the ASCII
code that is in the brackets. Eg - print chr$(65) - will display
A. See ASC.
CLEAR
CLEAR is a useful command which clears all variables and
memory banks defined by the current program. It also resets thee
read pointer to the first data statement in the program.
DATE$(var)
DATE$ is a reserved variable that holds the current date. If
you haven't got a clock card then this needs to be set directly
using the format - date$="DD/MM/YYYY" where DD is the day,MM is
the month and YYYY is the year. Eg date$="03/09/1989" sets the
date to the 3rd September 1989.
DEC num var
Just DECreases a number variable by 1. Inc. Eg - A=1:dec
A:print A will display 0.
DFREE
DFREE is a reserved variable that holds the amount of free
disk space on the current disk in the drive. Eg - print dfree -
might display 349304 is you have a freshly GEM formulated single
sided disk in the drive.
DIM num var/var(num var)
Dim DIMensions a variable ready for holding more than 1 piece
of information. The maximum you are allowed to dimension a
variable to is 65535 elements.Each of these elements are treated
separately. Eg dim a$(4):a$(1)="Hello":a$(2)="bye" and so on.You
can also dimension like this - dim A(4,4) or dim B$(8,10,10) etc.
These are used like normal dimensioned variables - Ie
A(1,1)=10:A(1,2)=20:B$(1,1,1)="Hello" etc etc.
DRIVE$
DRIVE$ is a reserved variable which holds the letter of the
current drive.If you are using drive A then - print drive$ - will
display A. to change the currently used drive you just have to
change drive$. Ie to change from drive A to drive B just enter
drive$="B".
DRVMAP
DRVMAP is a variable that holds a list of the drives connected.
The list is in the form of a binary number. Each digit in the
number contains the status of one the drives,starting with bit
0.Ifif the number is 1 then this means that the drive is connected
to the computer.Bit 0 holds info on drive A,bit 1 on drive B and
so on. Eg - print bin$(drvmap,32) - will probably display 30 0's
and 2 1's - if you only have drive A + B attached. Note that
DRVMAP always assumes a minimum of 2 drives even if you only have
a standard ST.
ERRL
ERRL holds the line number of the last error it came across in
a program. Type in this small program to see what I mean:
10 on error goto 30
20 print"This is an error line!":end
30 print"error in line";errl:end
ERRN
ERRN holds the error number of the last error it came across
in a program.Type in the program for ERRL but replace line 30 with
:30 print"error number";errn:end - to see this reversed variable
in operation.
FALSE
FALSE simply equals the number 0. Whenever you ask the
computer a question like - if Q>6 then .... - then a value is
produced to determine whether the condition is true or false. If
it is true then the value will equal minus 1 else if it is false
then it will hold 0. You can use this in your programs. Eg:
10 if x>10=false then print"X is lower than 10" else print "X is
higher than 10"
In this example however the use of false is pointless as it could
have been ommited.There are some ways of using false to your
advantage though. See true.
FILESELECT$(var,var,num var)
FILESELECT$ will bring up a fileselector box for you to pick a
file from.The first variable in the brackets holds the search
pattern, eg "*.bas". The second variable is optional and holds the
title for the fileselect box, eg "Load a file". The last number
variable is also optional and holds the border type for the
fileselect box. The format of this function is
var=fileselect$(var,var,num var). The var before the fileselect$
bit is the variable which will hold the name of the file you
choosewhile in the box. Eg - a$=fileselect$("*.bas","save a
file",4).Once you enter this line and choose a filename then a$
will hold that name - which you could then use with load or
save,eg load a$ or save a$. If you select quit from the fileselect
box the a$ will hold nothing,it will be an empty string.
FKEY
FKEY can be used to read the function keys directly without
having to use scancode to do it.FKEY will hold 1 if you press F1,2
if you press F2 and so on until FKEY will hold 20 if you press
F20(shift+10).Eg A$=fkey.
FLIP$(var)
FLIP$ simply reverses the order of the characters in the
specified string. Eg :a$="HELLO":a$=flip$(a$):print a$. Once
entered it should display "OLLEH".