The text of a manual · part 9 of 26
Videx BASIC for DuraTrax, LaserLite, LaserLite Pro, and LaserLite Mx Data Collectors, pages 81 to 90
Pages 81 to 90 of 252
The original document is the PDF (765 KB). This is its text as extracted, unedited; tables and drawings read best in the PDF, and each page heading opens it at that page.
For the Videx DuraTrax, Videx LaserLite, Videx LaserLite Mx and Videx LaserLite Pro
Page 81
CONST Statement • Action Introduces a named constant value. • Syntax CONST constantname = expression {, constantname = expression} • Parameters Argument constantname expression
Description A name following the same rules as a BASIC variable name. You may add a type-declaration character (% or $) to the name to indicate its type, but the character is not part of the name. Any expression that can be reduced to a simple constant value; e.g., chr$(13) + "Hi!"
• Remarks The constant name being introduced must not have been referred to on any previous lines. If you use a type-declaration suffix in the name, you may omit the suffix character when the name is used, as shown in the following example: CONST MAXDIM% = 250 . . . DIM AccountNames$ (MAXDIM)
If you omit the type-declaration suffix, the constant is assumed to be an integer.
Chapter 4 Statement & Function Reference
73
Page 82
Constants must be defined before they are referenced. The following example produces an error because the constant ONE is not defined before it is used to define TWO (constants are defined from left to right): CONST TWO = ONE + ONE, ONE = 1
A common programming practice is to use a statement like the following: FALSE = 0 TRUE = NOT FALSE
Constants offer several advantages over using variables for constant values: 1. Constants can be defined only once for an entire module. 2. Constants cannot be inadvertently changed. 3. Constants produce more efficient code than using variables. 4. Constants make programs easier to modify. The following program fragment declares a single constant to dimension a series of arrays. To increase or decrease the size of the arrays, it is necessary to change only the value of the CONST statement. CONST MAXCUST = 250 . . . DIM AccountNumber$(MAXCUST), Balance(MAXCUST) DIM Contact$(MAXCUST), PastDueAmount(MAXCUST) . . .
74
Chapter 4 Statement & Function Reference
Page 83
• Examples REM CONST Statement '* This example uses the NOT operator in a CONST expression. CONST FALSE = 0, TRUE = NOT FALSE CLS PRINT "FALSE = "; STR$(FALSE) PRINT "TRUE = "; STR$(TRUE); BEEP SLEEP 0 CLS
Output: FALSE = 0 TRUE = -1
See also the WHILE...WEND example.
Chapter 4 Statement & Function Reference
75
Page 84
DATE$ Function • Action Returns a string containing the current date. • Syntax nowDate$ = DATE$ ( ) • Parameters None • Remarks The DATE$ function returns a ten-character string in the form MM-DDYYYY, where MM is the month (01–12), DD is the day (01–31), and YYYY is the year (1964–2063). See also TIME$. • Returns The date as a ten-character string.
76
Chapter 4 Statement & Function Reference
Page 85
• Example REM DATE$() Function Dim nowDate$, convDate$ CLS nowDate$ = DATE$() PRINT "Date is :" PRINT nowDate$; SLEEP 0 GOSUB make_date CLS PRINT "Date is :" PRINT convDate$; SLEEP 0 END ' ' make_date ' description: Convert an OS date "MM-DD-YYYY" ' into a TimeWand I style time "YYYYMMDD" ' make_date: nowDate$ = DATE$ convDate$ = RIGHT$(nowDate$, 4) convDate$ = convDate$ + LEFT$(nowDate$, 2) convDate$ = convDate$ + MID$(nowDate$, 4, 2) RETURN
See also TIME$ example number 1.
Chapter 4 Statement & Function Reference
77
Page 86
DIM Statement • Action A declaration statement that names one or more variables and allocates storage space for them. • Syntax DIM variable$ [(upperbound%)] [* max%] {, single} single • Parameters Argument variable$ upperbound% max%
Description A BASIC variable name. The highest subscript (as an integer) to define the dimension of the array. The lowest subscript is always 0. The maximum size for a particular string.
• Remarks In some cases, this is no different than just using the named variable in an expression. The name being introduced must not have been referred to on any previous line. The syntax illustrates that more than one variable can be handled in a DIM statement. The term single represents allocating space for one variable; that is, variable$ [(upperbound%)] [*max%] = single. If the upperbound% for an array is specified after the variable name, then an array is allocated with indexes from 0 to the upperbound%, inclusive. (Unlike some implementations of BASIC, it is only possible to have 0 for the lower bound of the array.)
78
Chapter 4 Statement & Function Reference
Page 87
If max% is specified for a string variable (after the * character), then the variable will be allocated with room for the specified number of characters. Otherwise, 31 characters is used by default. The following statements are examples: DIM A (5) 'integer array with 6 elements (0 to 5) DIM B$*8 'string with maximum of 8 characters DIM C$(5)*8 'an array of 6 strings, each with a 'maximum 8 characters DIM A (5), B$*8, C$(5)*8 'the three previous examples on one 'command line
It is good programming practice to put the required DIM statements at the beginning of the program outside of any loops. • Example REM DIM Statement DIM question$(9) * 12
'dim an array of 10 questions; 'up to 12 chars each
FOR i = 0 to 9 question$(i) = "QUESTION " + STR$(i+1) 'stuff array beginning with question 1 NEXT i FOR i = 0 TO 9 CLS PRINT "Element "; STR$(i) 'display the array's elements PRINT question$(i); SLEEP 2 NEXT i
Chapter 4 Statement & Function Reference
79
Page 88
DO...LOOP Statement • Action Repeats a block of statements (repeated while a condition is true or until a condition becomes true). • Syntax 1 DO [ (WHILE | UNTIL ) integerexpression% ] [statementblock] LOOP • Syntax 2 DO [statementblock] LOOP [ (WHILE | UNTIL ) integerexpression% ] • Parameters Argument integerexpression% statementblock
Description Any expression that evaluates to true (nonzero) or false (0). One or more BASIC statements to be repeated.
• Remarks The DO condition is tested before each iteration of the loop, and the LOOP condition is tested after each iteration of the loop. The integerexpression% is considered to be true if it is nonzero and false if it is zero.
80
Chapter 4 Statement & Function Reference
Page 89
You can use both conditions in the same loop, but typically one (and only one) condition will be used for any given loop. It is possible to use no conditions. In this case, the loop must be exited with an EXIT statement (or some other mechanism). You may use a DO...LOOP statement instead of a WHILE...WEND statement. The DO...LOOP is more versatile because it can test for a condition at the beginning or at the end of a loop. See also WHILE...WEND and FOR...NEXT. • Example The following two examples show how placement of the condition affects the number of times the block of statements is executed. In the first example, the test is done at the beginning of the loop. Because Q is not less than 10, the body of the loop (the statement block) is never executed. REM DO...LOOP Statement example 1 'DO...LOOP with test at top of loop. 'Output shows that loop was not executed. DIM Q Q = 10 PRINT "Beg. Q value:";Q DO WHILE Q < 10 Q = Q + 1 LOOP PRINT "End Q value:";Q; SLEEP 0 CLS
Output: Beg. Q value: 10 End Q value: 10
Chapter 4 Statement & Function Reference
81
Page 90
The following example tests Q at the end of the loop, so the statement block executes at least once. REM DO...LOOP Statement example 2 'DO...LOOP with test at bottom of loop. 'Output shows that loop was executed once. DIM Q Q = 10 PRINT "Beg. Q value:";Q DO Q= Q + 1 LOOP WHILE Q < 10 PRINT "End Q value:";Q; SLEEP 0 CLS
Output: Beg. Q value: 10 End Q value: 11
In general, test at the end of a loop only if you know that you always want the body of the loop executed at least once.
82
Chapter 4 Statement & Function Reference