A DataBasic program consists of a sequence of instructions written as a set of DataBasic statements. Other program elements include: labels which identify a statement for referencing purposes; comment lines which annotate the program to enhance readability; and blank lines which can be used to improve the appearance of the program.
More than one statement can appear on the same program line, in which case they must be separated by semicolons. For example:
X=0; Y=1; GOTO 50
Note, however, that it is easier to use the DataBasic Debugger if only one statement appears on each line.
A statement can be continued onto the next line by appending an ellipsis (...) at the end of the first line. For example:
PRINT "THIS IS AN EXAMPLE OF":... "LINE CONTINUATION"
An identifier is simply a name given to a symbol, variable or subroutine. In DataBasic, the first character of an identifier must be a letter. Subsequent characters may be letters, digits, periods, underscores, dollar or pound signs (depending on the character in use), or percent signs. The following are all legal identifiers:
S v13 INVOICE.NO var B...$%
Note that DataBasic is case sensitive, so the following are different identifiers:
MY.IDENTIFIER my.identifier
Also, identifiers cannot be the same as any of the keywords used for other purposes in DataBasic (see Reserved Words).
DataBasic recognises a group of words that are reserved for special usage and cannot be used as identifiers.
In most cases, if you inadvertently attempt to use a reserved word in a program, the first indication is that the program fails to compile. The error message(s) will not reflect the use of a reserved word but give indications such as "Bad Statement." If the reserved word is nested within a loop or FOR/NEXT statement, the bad statement message might refer to the beginning of the loop.
If you use a reserved word as a variable name or a statement label in a long program, you will find it difficult to debug the program. The best word of advice is: learn the list of reserved words given below and avoid using any of them other than for their reserved function.
The following words may not be used as identifiers:
ACCESS | AND | AT | BEFORE |
BY | CAPTURING | CAT | CHAIN |
CONVERT | DO | ELSE | EQ |
FOR | FROM | GE | GO |
GOSUB | GOTO | GT | IN |
INCLUDE | LE | LOCKED | LT |
MATCH | MATCHES | NE | ON |
OR | PASSDATA | PASSLIST | REMOVE |
REPEAT | REPLACE | RETURNING | RTNDATA |
RTNLIST | SETTING | STEP | SYSTEM |
THEN | TIMEOUT | TO | UNTIL |
USING | WITH | WHILE |
The following additional words are the names of functions and may not be used as the names of dimensioned arrays:
ABS | ALPHA | ASCII | ASSIGNED |
BCC | BITCHANGE | BITCHECK | BITLOAD |
BITRESET | BITSET | CHANGE | CHAR |
CHECKSUM | COL1 | COL2 | COMPARE |
COS | COUNT | CRC | DATE |
DCOUNT | DECRYPT | DELETE | DOWNCASE |
DQUOTE | DTX | EBCDIC | ENCRYPT |
EXP | EXTRACT | FIELD | FMT |
FOLD | GETMSG | GROUP | ICONV |
INDEX | INSERT | INT | LEN |
LOWER | LN | MAXIMUM | MINIMUM |
MOD | NOT | NUM | OCONV |
PWR | PTR | RAISE | RECORDLOCKED |
REM | REMOVE | REPLACE | RND |
ROUND | SENTENCE | SEQ | SIN |
SORT | SOUNDEX | SPACE | SPOOLER |
SQUOTE | SQRT | STATUS | STR |
SUM | SUMMATION | TAN | TIME |
TIMEDATE | TRANSQUERY | TRIM | TRUNC |
UNASSIGNED | UPCASE | VARVAL | VARTYPE |
VARVALTYPE | XTD |
A statement label allows branching to the labelled statement from elsewhere in the program. The label must be the first thing on the line, preceding the statement it references, or on a line on its own.
Both numeric and alphanumeric labels can be used. Alphanumeric labels must obey the rules for identifiers, except that they are terminated with a colon (:), while numeric labels can contain only digits and a single decimal point, and can optionally end with a colon. One or more spaces must separate the label from any other statements on the same line. The colon does not form part of the label and must be omitted when referencing a label.
In the example below, LOOP and FINISH are both alphanumeric labels, while 10, 20, 30 and 30.5 are numeric labels (30 includes a terminating colon). Note that all references to these labels omit the colon.
LOOP: INPUT X IF X="QUIT" THEN GO FINISH IF NOT(NUM(X)) THEN GOTO LOOP ON X GOTO 10,20,30,30.5 10 PRINT "FIRST"; GO LOOP 20 PRINT "SECOND"; GO LOOP 30: PRINT "THIRD"; GO LOOP 30.5 PRINT "FOURTH"; GO LOOP FINISH: END
Comments are included in a program to annotate the code, so as to enhance readability and provide a useful documentation tool. They can be inserted anywhere in the program without affecting its execution.
A comment is identified by including a remark identifier at the beginning of each comment line. This can be one of three types:
For example, the statements below are all valid comment lines:
REM THESE STATEMENTS DO NOT
* AFFECT PROGRAM EXECUTION
The following multi-statement line contains an assignment followed by a comment:
X=Y+3; ! ASSIGN SUM OF Y+3 TO VARIABLE X
The exclamation mark (!) is a special case. When used, it causes a line of asterisks to be printed when the program is BLISTed.
A comment can be inserted anywhere in the program, but normally for optimum readability, it will be, either on a line all by itself, or at the end of a statement. When placed at the end of a statement, a semi-colon (;) must separate it from the preceding statement. For example:
INCR=INCR+1; *Increments the counter
If a comment is carried over onto the next line, the remark identifier (*, REM or !) must be inserted at the beginning of each comment line. The comment(s) can also be included within a multi-line statement. For example:
PRINT "THIS IS AN EXAMPLE OF":...; *This is a *comment embedded between continued lines. "LINE CONTINUATION"
For more information on the use of the remark identifier, refer to the REM statement description.
Excess blank spaces between elements of a program line and whole blank lines in a program are ignored and do not affect program execution, unless they are part of a character string. For example:
REM Program to print the ... blank line REM numbers from 1 to 10. INCR=1 5 PRINT INCR IF INCR = 10 THEN STOP ... blank line INCR=INCR+1 GOTO 5 END
In the above example the blank lines inserted between lines of code or comment lines are ignored. On the other hand in the example below:
REM Program to print 'HELLO' message MESSAGE="H ELLO" PRINT MESSAGE END
The program prints H ELLO
, not HELLO
.
In this case, the blanks included in the string are inserted in the output and
are not ignored.
A DataBasic program is stored as an file item and is referenced by the item-id. The item-id is the name given to it when it is created using one of the Reality editors. An individual line within a DataBasic program is an attribute.
When creating a program item you must not begin the program item-id with a $ or £ sign. This is used by DataBasic to identify a compiled program. If you do, the system will ignore the request to compile and the software displays the message:
'$$xxxx' NOT ON FILE
Also, you must not use an asterisk (*) in a program item-id as this is used as a separator in POINTER-FILE and problems will result if the program is cataloged.