Program Elements

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.

Multi-statement Line

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.

Line Continuation

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"

Note: The COMMA.CONT compatibility option allows you to a comma instead of an ellipsis.

Identifiers

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 the DataBasic compiler (BASIC command) is case sensitive, so the following are different identifiers:

MY.IDENTIFIER
my.identifier

Note: Programs with mixed case identifiers scan be compiled with the COMPILE command.

Also, identifiers cannot be the same as any of the keywords used for other purposes in DataBasic (see Reserved Words).

Go to top buttonStatement Labels

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

Go to top buttonReserved 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:

ABORT ACCEPT ASSIGN ATTACH
BEGIN CALL CALLA CASING
CHAIN CLEAR CLEARDATA CLEARFILE
CLEARSELECT CLOSE CLOSESEQ COLLECTDATA
COM COMMON CONNECT CONTINUE
CONVERT CREATE CRT DATA
DEBUG DEFINE DEL DELETE
DELETELIST DELETESEQ DETACH DIM
DIMENSION DISCONNECT ECHO ECHOOFF
ECHOON ENTER EQU EQUATE
EXECUTE EXIT FILELOCK FILEUNLOCK
FIND FLUSH FOOTING FOR
GARBAGECOLLECT GET GETCOUNT GETLIST
GO GOSUB GOTO GROUPSTORE
HEADING IF IFDEF IFUNDEF
IN INCLUDE INPUT INPUTCLEAR
INS LOCATE LOCK LOOP
MAT MATBUILD MATINPUT MATPARSE
MATREAD MATREADU MATWRITE MATWRITEU
NULL ON OPEN OPENSEQ
PAGE PAUSE PERFORM POSITION
PRECISION PRINT PRINTER PRINTERR
PROC PROMPT PUT READ
READBLK READLIST READNEXT READPREV
READSEQ READTX READU RECEIVE
RECORDLOCKU RECWAIT RELEASE REM
REMOVE RETURN REWIND RQM
RTNDATA SEEK SELECT SELECTE
SEND SHARE SLEEP STOP
TCLREAD TRANSABORT TRANSEND TRANSTART
UNDEFINE UNLOCK VARVALSET WAKE
WEOF WEOFSEQ WRITE WRITEBLK
WRITELIST WRITESEQ WRITET WRITETX
WRITEU WRITEV WRITEVU

 

The following additional words are the names of intrinsic functions and may not be used as the names of external functions or dimensioned arrays:

ABS ABSS ACCESS ADDS
ALPHA ANDS ASCII ASSIGNED
BCC BITCHANGE BITCHECK BITLOAD
BITRESET BITSET CATS CHANGE
CHAR CHARS CHECKSUM COL1
COL2 COMPARE CONVERT COS
COUNT COUNTS CRC DATE
DCOUNT DECRYPT DELETE DIV
DIVS DOWNCASE DQUOTE DTX
EBCDIC ENCRYPT ENVIRON EQS
EREPLACE EXP EXTRACT FIELD
FIELDS FILEINFO FILEPATH FMT
FOLD GES GETMSG GROUP
ICONV ICONVS IFS INDEX
INSERT INT LEFT LEN
LENS LES LN LOWER
MAXIMUM MINIMUM MOD MODS
MULS NEGS NES NOT
NOTS NUM NUMS OCONV
OCONVS ORS PAUSE PWR
QUOTE RAISE REAL.ACCESS REAL.SYSTEM
RECORDLOCKED REM REMOVE REPLACE
RIGHT RND ROUND SADD
SENTENCE SEQ SEQS SIN
SORT SOUNDEX SPACE SPACES
SPLICE SPOOLER SQRT SQUOTE
SSUB STACKING STATUS STR
STRS SUBS SUM SUMMATION
SWAP SYSTEM TAN TIME
TIMEDATE TRANS TRANSQUERY TRIM
TRIMB TRIMF TRUNC UNASSIGNED
UPCASE VARTYPE VARVAL VARVALTYPE
WAKE XLATE XTD  

 

Note: The case-sensitivity of these keywords depends on which command you use to compile your code: the BASIC command is case-sensitive (all keywords must be entered in upper case) and the COMPILE command case-insensitive (the case of keywords is ignored; CASING, casing and CasinG, for example, are treated as the same keyword).

Go to top buttonComments

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.

Go to top buttonBlank Spaces and Lines

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.

Go to top buttonProgram Storage

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.

Naming a Program

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.

Go to top button