Programming Hints
Using System Delimiters
Reality uses standard attribute, value and subvalue delimiters. These should be referenced using the predefined symbols @AM, @VM and @SM (or @SVM).
Cursor Positioning
Reality uses standard Cursor Positioning Characters. It is recommended that these are EQUATE'd to symbol names, then they can be referenced in a program by their symbol name. For example:
EQU UP TO CHAR(26)
EQU DOWN TO CHAR(10)
EQU LEFT TO CHAR(21)
EQU RIGHT TO CHAR(6)
EQU BELL TO CHAR(7)
Of course, you can use extended cursor addressing such as, @(-10), for all of the above. However, the extended cursor addressing symbols can only be assigned to variables; they cannot be EQUATE'd to a symbol.
Opening Files
The OPEN statement is very time-consuming and should be executed as few times as possible. All files should be opened to file variables at the beginning of the program; access to the files can then be performed by referencing the file variables.
Repeating Operations
Operations should be predefined rather than repetitively performed. This operation, for example:
X= SPACE(9-LEN(OCONV(COST,'MD4'))):OCONV(COST,'MD4')
should be written as follows:
E= OCONV(COST,'MD4')
S= SPACE(9-LEN(E))
X= S:E
The same is true for the following operation:
FOR I=1 TO X*Y+Z(20) . . . NEXT I
This should be written as follows:
TEMP=X*Y+Z(20) FOR I=1 TO TEMP . . . NEXT I
Unknown Number of Values
The following LOOP statement could be used to access an unknown number of values from an attribute (including null values):
EQU VM TO CHAR(253)
READV ATTR FROM ID, ATTNO ELSE STOP
VNO=0
LOOP
VNO=VNO+1
VALUE=FIELD(ATTR,VM,VNO)
WHILE COL2() #0 DO
PRINT VALUE
REPEAT
Modifying a Program
There are three simple preliminary steps which will simplify the task of modifying a program, especially if it has been changed and added to since it was first written. In such circumstances, it is necessary to sort all of the variables used in the program into a meaningful order so that the program's structure and method of operation are more apparent.
-
BASIC file-specifier item-id (X
Compiling a program with the X option builds a cross-reference table of labels and variables and puts the items in the CSYM file (CSYM must already be defined in your account).
-
BREF (P
The BREF command displays the cross-reference table which lists all the variables used in the program as well as the program line numbers where each variable is accessed. It also uses * (asterisk) to denote the lines where the variable may change value. The P option sends the listing to the printer.
-
BLIST file-specifier item-id (L,U,P
The BLIST command lists the DataBasic source code in a more readable format and clarifies which END goes with which IF, and which NEXT goes with which FOR. The selection of options in the example above control the format:
L Prints a period (.) at each level of indentation, giving a more logical structure.
U Updates the source code with the logical indenting.
P Sends the listing to the printer.
Having performed these three steps, you will be better prepared to start making changes to the program.