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 permission 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 e.g. 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:
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. e.g. 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 stands for ABSolute and will return the absolute value of a number, regardless of the sign. e.g. – print abs(-73) – will display 73.
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).
Used to convert numbers into binary strings, BIN$ is one of those functions I rarely use! e.g. – print bin$(63) – will display %111111 which is the binary value for 63.
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 is a useful command which clears all variables and memory banks defined by the current program. It also resets the read pointer to the first data statement in the program.
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. e.g. 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 is a reserved variable that holds the amount of free disk space on the current disk in the drive. e.g. – 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. e.g. 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 – e.g. A(1,1)=10:A(1,2)=20:B$(1,1,1)=”Hello” etc etc.
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 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. If 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. e.g. – 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 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 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 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. e.g: 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$ will bring up a fileselector box for you to pick a file from.The first variable in the brackets holds the search pattern, e.g. “*.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 choose while in the box. e.g. – 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, e.g. 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 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). e.g. A$=fkey.
FLIP$ simply reverses the order of the characters in the specified string. e.g: a$=”HELLO”:a$=flip$(a$):print a$. Once entered it should display “OLLEH”.