SmartBASIC Tutorials
Chapter 1
by ?


The computer is very fast, very accurate and very stupid. It
responds when told specifically what to do in a language that it
understands, but it can not reason or infer meanings or
intentions. This discussion, including illustrations, is designed
to enhance your understanding of the language so you can
communicate with ADAM and, at the same time, hopefully be
entertained a little. The order of introducing concepts is for
convenience only in trying to accomplish those goals.

Programing is not an exact endeavor with a right or wrong answer.
Obviously there must be an output consistent with the purpose of
the program and that output must be correct. The method of
getting there, however, will vary and all can do the job. Yes,
some programs are better than others but that judgement is based
on two specifics, memory used and speed of execution, and an
abstract concept sometimes called "user friendliness". As long as
there is sufficient momory available, friendliness may be more
important to the home computer user than speed.

There are two parts to programing. The first is the knowledge of
commands and what the computer can do. The second is taking your
time to think through what you want to do and piece by piece, how
to get it done. That is the logic of the program. You can't use
one without the other!

The first step in this set of instructions is to load SmartBASIC
into the computer. If there are questions on loading, consult the
instruction manual.

Let's start with the RETURN key. As you read this material, you
find punctuation marks and paragraphs to help you separate
thoughts. Computers do not understand that concept, it is too
general. Instead, when you have completed a statement or a
command, or give the computer the requested information, such as a
number, press the RETURN key. The information will then be acted
upon by the computer. Sometimes, this is known as ENTER. The
action is just the same, press the RETURN key. At first, you will
be reminded to do this by the RETURN, ENTER, or the symbol (CR),
carriage return.

The computer looks at the first key in a series. If thqt key is a
number, it expects the information to be a numbered statement in a
program. That number cannot be larger than 65535. If it is, the
number will be rejected. More about that in a later
session. If, however, the first key pressed is a letter, the
computer then expects a COMMAND that can be acted upon in the
IMMEDIATE mode. The first word following a number must be a
command.

The list of commands is shown in the instruction manual and will
not be repeated as such in this document. Let's experiment just a
little bit. First, however, a few words about the computers
memory. You can't physically hurt the computers menory, but you
can sure confuse it. Sometimes, you may cause it to go off on its
looking for sometning that it can't find and you don't know what
it is. The cursor will either quit blinking or even
disappear. You may have to reboot SmartBASIC again in order to
unlock the computer. In so doing, you will lose all of the
information that you have put into memory, but no other harm has
been done.

Type 1234(CR) (remember our symbol for RETURN)

Other than the cursor moving to the next line, nothing happened on
the screen. why? The computer was expecting a program statement.
Since the entry was a number, it was prepared to save the material
following the number, but no other information was
given. As there was nothing to do the computer stored "nothing"
as instruction number 1234. Actually, it just forgot the whole
thing including the numbered instruction. There was nothing
there.

One of the most frequently used BASIC Commands is the word PRINT.
Try typing the word PRINT and (CR). Once again, other than the
cursor moving down a line, nothing seemed to have happened. That
is so because we gave it nothing to print - the command needs more
information.

Try PRINT 4(CR). Now the numeral 4 is printed on the screen. Try
printing several different numbers to get the feel of the
operation. Now let's try something a little different. Type
PRINT 2+2(CR). You get the answer 4. Note that the equal sign
(=) was not used - it is unnecessary and will even confuse ADAM.
Try it!

Can the computer do anything besides add? Yes, but the symbols
used in the commands may be different than those you are used to
seeing. They are:
+ Addition
- Subtraction
* Multiplication
/ Division
^ Exponentation

A word about exponentation. This raises a number to a power and
is entered as:

PRINT 2^3(CR) for exawmple.

The computer will return 8, or 2 raised to the third power. Try
several examples of all the operations.

By now, you must be tired of typing the word PRINT. BASIC
provides for that by giving you a shortcut. Instead of typing the
word PRINT, you can type the question mark symbol "?" and the
computer understands that it is to PRINT. Try several different
tests of that command.

By the way, if the mess on the screen is bothering you, enter the
word HOME(CR). Presto, the screen is now cleared of all the work
so far. Something else, ADAM is not particular whether you use
upper or lower case letters to talk to it.. While COMMANDS will
frequently be shown in upper case in this text, they may be
actually entered in lower case letters.

What happens if you type PRINT X? Try it and see. The computer
answers with a "0" (zero). It printed out the value of the
variable X which at this point is zero. Until a variable is set
to equal
something, a zero will always be returned. Noiw type in :

LET X = 100(CR)
PRINT X

The value of the variable was printed.

Probably, by this time, you have encountered ERROR MESSAGES. ADAM
is quite good about returning information that error has been
encountered, about where in the statement the error is, and the
nature of the error. Not all computers are this friendly-- they
wait until you try to run the program and then just tell you that
an error has been made and in what program step it has occured.
To illustrate an ERROR MESSAGE, try typing the
following:

PRANT X
The computer does not recognize the word PRANT, thus it returns
the message. In the immediate mode, there is no choice but to
retype the correct command and enter it again. The carat will
usually point to the column where the computer thinks the error
occurred although it is really pointing out that it expects
something at that location in the statement that wasn't found.

A partial listing of ERROR MESSAGES is shown in Appendix C, pages
1 - 4, of the revised edition of the Smart BASIC programing
manual. You may wish to review these. They will help you as you
debug programs that you write.

What if we wish to print a word, rather than a number or the value
of a variable? That is simple-- just put the information that is
to be printed inside QUOTATION MARKS. The characters may be
letters, symbols, or numbers and there is no restriction as to the
order. Try:

PRINT "John Jones"(CR)

Try your own name; your street and address; think up some examples
of your own. Try:

? "2+2"(CR)

The quotation marks tell the computer to print the material, don't
worry about doing what it says.

There is a limitation inherent in SmartBASIC. ADAM cannot print a
quotation mark, not an unusual limitation and it is generally
inherent in BASIC although some systems do make provisions to
handle the problem.

There are some commands that will erase material from RAM (Random
Access Memory). One such command is NEW. When "NEW" is entered,
all program steps are removed from memory. Be careful when using
this command so that material you wanted to keep is not lost.
When starting to enter a program in RAM, it is a good idea to
execute "NEW" to make sure RAM is clear. If there is a program in
memory and you start to enter another, you will probably make a
mess of both the old and new.

Another command is CLEAR. CLEAR will erase all variables,
including arrays. Arrays will have to be DIMensioned again (see
arrays). Once again, be sure you want to remove all vartiables
before this command is used. In the immediate mode, enter the
following and observe what happens:

B = 1000(CR)
DIM a$(20,20)(CR)
a$(20,20) = "TESTING"(CR)
? a$(20,20)(CR)
? B(CR)
CLEAR(CR)
? B(CR)
? a$(20,20)(CR)

The last PRINT B command resulted in zero as the CLEAR command
erased the previous value. The ERROR MESSAGE "?Bad Subscript
Error" translates to the computer not having an array called a$
with that many rows and columns. Once again, CLEAR destroyed the
a$ array we had created earlier with the DIM a$ command.

Now let's try our hand at a little simple programing. Try typing
the following:

NEW(CR)
10 FOR i = 1 to 10(CR)
20 ? "John Jones"(CR)
30 NEXT i (CR)
40 END(CR)


Did you remember that (CR) meant to press the RETURN key? When you
get to the end of a complete statement, pressing the RETURN key
informs the computer that you are done with that statement.
Hencefourth, the Return key prompt will be omitted.

Now, let's increase our BASIC vocabulary some. Try entering, in
the immediate mode, LIST. A complete listing of your program is
shown on the screen.

Now try LIST 10. Just statement number 10 was listed.

Try LIST 20, 30. Two statements are printed out since there were
no other statements between those two.

The LIST commands are usefull in seeing what your program
contains, editing the program, or making other revisions. Had you
first entered PR#1, you would have gotten a printed copy of the
program from your printer. If you have entered PR#1, be sure to
enter PR#0 to turn the printer back off before continuing to enter
data. If you wish a printed copy of just the material on the
monitor screen, hold down the CONTROL key and press the letter
"p".
 

Back to Top