This topic presents a number of general coding techniques which the programmer should keep in mind when writing mvBASIC programs.
The MultiValue system uses standard attribute and value delimiters. Each of these should be defined in the initialization portion of the program and referenced as needed by a variable name. For example:
AM = CHAR(254) |
Attribute Mark |
VM = CHAR(253) |
Value Mark |
SVM = CHAR(252) |
Subvalue (or Secondary Value) |
Mark |
|
Cursor positioning should be controlled by the following PRINT statements, using @ functions and the character functions:
ERASE SCREEN HOME CLEAR TO END OF SCREEN CLEAR TO END OF LINE START BLINK STOP START PROTECT STOP PROTECT BACKSPACE UP 1 LINE DOWN 1 LINE RIGHT 1 CHARACTER BELL |
= PRINT @(-1) = PRINT @(-2) = PRINT @(-3) = PRINT @(-4) = PRINT @(-5) = PRINT @(-6) = PRINT @(-7) = PRINT @(-8) = PRINT @(-9) = PRINT @(-10) = PRINT CHAR(10) = PRINT CHAR(6) = PRINT CHAR(7) |
The OPEN statement is 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.
Program size can be reduced, with a corresponding increase in overall system performance, by reducing the amount of literal storage. For example:
PRINT 'RESULT IS ':A+B PRINT 'RESULT IS ':A-B PRINT 'RESULT IS ':A*B PRINT 'RESULT IS ':A/B |
These statements should have been written as follows:
MSG = 'RESULT IS' PRINT MSG: A+B PRINT MSG: A-B PRINT MSG: A*B PRINT MSG: A/B |
Operations should be predefined rather than repetitively performed.
The following operation, for example:
X=SPACE(9-LEN(OCONV(COST,'MCA'))): :OCONV(COST,'MCA') |
should have been written as follows:
E=OCONV(COST,'MCA') X=SPACE(9-LEN(E)):E Or optimally as: X=OCONV(COST,’MCA’) ’R#9’ |
In the same context, the following operation:
FOR I=1 TO X*Y+Z(20) . . . NEXT I should have been written as follows: TEMP=X*Y+Z(20) FOR I=1 TO TEMP . . . NEXT I |
The following LOOP construct could be used to access an unknown number of MultiValues from an attribute (including null values):
VM=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 |
See Also