home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
No Fragments Archive 10: Diskmags
/
nf_archive_10.iso
/
MAGS
/
POWERMAG
/
POWER16.MSA
/
POWER_16
/
STRINGVA.PWR
< prev
next >
Wrap
Text File
|
1985-11-20
|
6KB
|
149 lines
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
~Understanding Strings and Variables~
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
BY CHRIS SHARP
A variable, when used in computer
programming, simply means a letter
or string of letters which contain
a value. The value they can contain
can be numerical or alphanumerical.
For example we can tell STOS basic
to swap the letter A for 10 whenever
it see's an equation which needs a
variable like so -:
10 LET A=10
Or more simply...
10 A=10
The first example simply clarifies
things, so it is probably a good idea
to use the first method until you
get used to using variables in your
code.
All we have done is to tell STOS
Basic that the letter A should become
equal to the value of 10.
We can also tell STOS Basic that we
want a single letter to contain a
short message, so -:
10 LET A$ = "This is STOS Basic"
When this program is now run, the
message "This is STOS Basic" is
contained in the string A$.
Notice how when we want to include
Alphabetical characters in a
variable, we have to put a dollar
sign in front of the variable name.
Did you also notice how we have to
put inverted comma's around the
entire message?
A STRING is used to hold characters
and numbers, or just characters, is
called a STRING, or A STRING OF
CHARACTERS.
A VARIABLE can only be used to hold
numerical values such as 10 or 500.
The following are STRINGS OF
CHARACTERS -:
"Hello"
"123456789"
"STOS BASIC"
"XYZ123ABC"
"NUMBERS!"
The following are examples of
VARIABLES-:
1
65534
32767
127
44
We can also use multiple letters to
create a variable, so we could have
the following -:
ABCD = 10
XYZO = 50
However, note that we cannot use
Variables that contain the name of
a STOS Basic command, so the
following would be invalid -:
total = 10
Do you notice that because part of
the Variable contains the KEYWORD
to, it is invalid?
The same applies for strings, so
TOTAL$ = "HELLO"
would be invalid. However, there are
so many names for strings and
variables that we most probably would
never run out, even if the program
we were writing was so large that it
was spread out over 30 disks.
So, we can see that a variable is
a simple name for a letter equaling
a value, almost the same as algebra.
A string is simply a string of
letters, and the string name must
end with a dollar sign, which tells
STOS Basic that it is a string.
It is possible, once you learn more
about variables to start assigning
a variable to another variable, so-:
A = 10
B = 10
C = A + B
If the three previous lines were
typed in, then C would become equal
to 20, which is the sum of A + B.
Also possible is using the other
mathematical functions -: Multiply,
divide and subtract, so-:
A = 10
B = 10
C = A - B
If the three previous lines were
typed in, C would become equal to
0, because 10 - 10 = 0.
Basically, Variables are only needed
when we don't know for definite what
any certain value will be in a
program, and it is likely to change
at any time. For instance if we had
a program which had to run a loop X
number of times we could simply say
FOR LOOP = 1 to X, and this would be satisfactory for our program.