SECTION 19
19.1 VARIABLES
The Commodore 128 uses three types of variables in BASIC. These are: normal numeric, integer numeric, string (alfanumeric).
Normal NUMERIC VARIABLES, also called floating point variables, can have any exponent value from 10 to +10, with up to nine digits of accuracy. When a number becomes larger than nine digits can show, the computer displays it in scientific notation form, with the number normalized to one digit and eight decimal places, followed by the letter E and the power of 10 by which the number is multiplied. For example, the number 12345678901 is displayed as 1.23456789E+10.
INTEGER VARIABLES can be used when the number is from +32767 to 32768 (inclusive), and with no fractional portion. An integer variable is a number like 5, 10 or 100. Integers take up less space than floating point variables, particularly when used in an array (see below).
STRING VARIABLES are those used for character data, which may contain numbers, letters and any other characters the Commodore 128 can display. An example of a string variable is "COMMODORE 128".
VARIABLE NAMES may consist of a single letter, a letter followed by a number, or two letters. Variable names may be longer than two characters, but only the first two are significant. An integer is specified by using the percent sign (%) after the variable name. String variables have a dollar sign ($) after their names.
EXAMPLES:
Numeric Variable Names: A, A5, BZ
Integer Variable Names: A%, A5%, BZ%
String Variable Names: A$, A5$, BZ$
ARRAYS are lists of variables with the same name, using an extra number (or numbers) to specify an element of the array. Arrays are defined using the DIM statement and may be floating point, integer or string variable arrays. The array variable name is followed by a set of parentheses () enclosing the number of the variable in the list.
EXAMPLE:
A(7),BZ%(11),A$(87)
Arrays can have more than one dimension. A twodimensional array may be viewed as having rows and columns, with the first number identifying the row and the second number identifying the column (as specifying a certain grid on the map).
EXAMPLE:
A(7,2), BZ%(2,3,4), Z$(3,2)
RESERVED VARIABLE NAMES are names reserved for use by the Commodore 128, and may not be used for any other purpose. These are the variables: DS, DS$, ER, EL, ST, TI and TI$.
KEYWORDS such as TO and IF or any other name that contain keywords, such as RUN, NEW or LOAD cannot be used as variable names.
ST is a status variable for input and output (except normal screen/keyboard operations). The value of ST depends on the result of the last I/O operation. In general, if the value of ST is 0, then the operation was successful.
TI and TI$ are variables that relate to the real time clock built into the Commodore 128. The system clock is updated every 1/60th of a second. It starts at 0 when the Commodore 128 is turned on, and is reset only by changing the value of TI$. The variable TI gives the current value of the clock in 1/60th of a second. TI$ is a string that reads the value of the real time clock as an 24hour clock. The first two characters of TI$ contain the hour, the third and fourth characters are minutes and the fifth and sixth characters are seconds. This variable can be set to any value (so long as all characters are numbers) and will be updated automatically as a 24hour clock.
EXAMPLE:
TI$="101530" sets the clock to 10:15 and 30 seconds (AM).
The value of the clock is lost when the Commodore 128 is turned off. It starts at zero when the Commodore 128 is turned on, and is reset to zero when the value of the clock exceeds 235959 (23 hours, 59 minutes and 59 seconds).
The variable DS reads the disk drive command channel and returns the current status of the drive. To get this information in words, PRINT DS$. These status variables can be used after a disk operation, like DLOAD and DSAVE, to find out why the red error light on the disk drive is blinking.
ER and EL are variables used in error trapping routines. They are usually only useful within a program. ER returns the last error encountered since the program was RUN. EL is the line where the error occurred. ERR$ is a function that allows the program to print one of the BASIC error messages. PRINT ERR$(ER) prints out the proper error message.
19.2 Operators
The BASIC OPERATORS include: ARITHMETIC OPERATORS, RELATIONAL OPERATORS and LOGICAL OPERATORS.
The ARITHMETIC OPERATORS include the following signs:
+ addition
 subtraction
* multiplication
/ division
^ raising to a power (exponentiation)
On a line containing more than one operator, there is a set order in which operations always occur. If several operators are used together, the computer assigns priorities as follows: First exponentiation, then multiplication and division, and last, addition and subtraction. If two operators have the same priority, then calculations are performed in order from left to right. If these operations are to occur in a different order, Commodore 128 BASIC allows giving a calculation higher priority by placing parentheses around it. Operations enclosed with parentheses will be calculated before any other operation. Make sure the equations have the same number of left and right parentheses, or a SYNTAX ERROR message is displayed when the program is run.
There are also operators for equalities and inequalities, called RELATIONAL OPERATORS. Arithmetic operators always take priority over relational operators.
= is equal to
< is less than
> is greater than
<= or =< is less than or equal to
>= or => is greater than or equal to
<> or >< is not equal to
Finally, there are three LOGICAL OPERATORS, with lower priority than both arithmetic and relational operators:
AND
OR
NOT
These are most often used to join multiple formulas in IF... THEN statements. When they are used with arithmetic operators, they are evaluated last (i.e. after + and ). If the relationship stated in the expression is true, the result is assigned an integer value of 1. If false, a value of 0 (zero) is assigned.
EXAMPLES:
IF A=B AND C=D THEN 100 
Requires both A=B and C=D to be true. 
IF A=B OR C=D THEN 100 
Allows either A=B, C=D, or both, to be true. 
A=5:B=4:PRINT A=B 
Displays a value of zero. 
A=5:B=4:PRINT A>3 
Displays a value of 1. 
PRINT 123 AND 15:PRINT 5 OR 7 
Displays 11 and 7. 
