The text of a manual · part 2 of 26
Videx BASIC for DuraTrax, LaserLite, LaserLite Pro, and LaserLite Mx Data Collectors, pages 11 to 20
Pages 11 to 20 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 11
Chapter 1 Videx BASIC The Videx BASIC character set contains alphabetic characters, numeric characters, and special characters. The alphabetic characters are the letters A–Z, either uppercase or lowercase, and the underscore character. The numeric characters are the digits 0–9. The special characters and their purposes are: Character <Enter>
Purpose Pressing the <Enter> key terminates input of a line Blank (or space)
$
Dollar sign (suffix for string data type)
%
Percent (suffix for integer data type)
'
Single quotation mark or apostrophe (comment indicator)
(
Left parenthesis
)
Right parenthesis
*
Asterisk (multiplication symbol)
+
Plus sign (addition symbol or concatenation operator)
,
Comma
-
Minus sign (subtraction symbol or prefix for negative number)
.
Period
/
Slash (division symbol)
:
Colon (separates statements on same line; ends line labels)
;
Semicolon
<
Less than
=
Equal sign (assignment symbol or relational operator)
>
Greater than
?
Question mark
|
Pipe (line continuation character) Chapter 1 BASIC
3
Page 12
Basic Program Line The BASIC program line has the following syntax: [line identifier] [statement] [: statement]...[comment]
Using Line Identifiers Videx BASIC supports alphanumeric line labels for line identifiers. An alphanumeric line label can be any combination of letters and digits, starting with a letter and ending with a colon. BASIC reserved words and type-declaration suffixes are not permitted. The following are valid alphanumeric line labels: Gamma: ShowList: TestB5: Case is not significant. The following line labels are equivalent: gamma: Gamma: GAMMA: Line labels may begin in any column, as long as they are the first characters other than blanks or tabs on the line. Blanks and tabs are allowed between an alphanumeric label and the colon following it. A line can have only one label.
4
Chapter 1 BASIC
Page 13
BASIC Statements A BASIC statement is either “executable” or “nonexecutable.” An executable statement tells the program what to do next (for example, telling it to read input, write output, open a file, or take some other action). In contrast, a nonexecutable statement performs tasks such as allocating storage for variables, or declaring and defining variable types. The following are nonexecutable BASIC statements: • REM or ' (comment notation) • CONST (defines constant) • DIM (allocates storage) A comment is a nonexecutable statement used to clarify a program’s operation and purpose; it is introduced by either a REM statement or a single quote character ('). The following two lines are equivalent: PRINT "Quantity remaining" PRINT "Quantity remaining"
REM Print report label. ' Print report label.
You may place more than one BASIC statement on a line, but a colon (:) must separate the statements, as illustrated below: FOR I=1 TO 5 : PRINT "Welcome friends." : NEXT I
If the BASIC statement exceeds the character length of your screen, use the pipe ( | ) character at the end of the line to let the program know that the BASIC statement continues onto the next line. End the statement with the <Enter> key or with a colon character. Every BASIC statement begins with a keyword and ends with either an end of the line (<Enter> key) or with a colon character. The one exception is assignment statements, where the initial keyword, LET, is optional.
Chapter 1 BASIC
5
Page 14
Notes:
6
Chapter 1 BASIC
Page 15
Chapter 2 Data Types Every variable in BASIC has a data type that determines what can be stored in the variable. There are two categories of data in BASIC: string data and numeric data. Each category includes elementary data types. The following section summarizes these data types.
Elementary Data Types - String All strings can have variable length up to a maximum size that is defined separately for each string. The default size of a string is 31 characters, but this can be changed to any value with the DIM statement (subject to Videx BASIC memory limitations). Strings are terminated by the null character (ASCII 0). (Note: A consequence of this is that it is not possible to write the null character to a string or to a file with Videx BASIC. See the discussions on the HEX$ function and TOUCH statement in Chapter 3 for more information on handling null characters in a string.)
Elementary Data Types - Numeric • Integer (two bytes) Integers are stored as sixteen-bit binary numbers ranging in value from -32,768 to 32,767.
Chapter 2 Data Types 7
Page 16
Integer Numbers All BASIC integers are represented as two’s complement values. This is the most common way of representing integer numbers on a computer. Integers use 16 bits (2 bytes) of memory. In two’s complement representation, positive values are represented as straightforward binary numbers. For example, BASIC would store an integer value of 4 as the following sequence of 16 bits: 0000000000000100
Negative values are represented as the two’s complement of the corresponding positive value. To form the two’s complement (the negative) of the integer value 4, first take the representation above and change all the ones to zeros and all the zeros to ones: 1111111111111011
Then, add one to the result: 1111111111111100
The final result is how BASIC represents -4 as a binary number. Because of the way two’s complement numbers are formed, every combination of bits representing a negative value has a 1 at the leftmost bit.
8
Chapter 2 Data Types
Page 17
Constants Constants are predefined values that do not change during program execution. There are two general types of constants: literal constants (such as numbers and strings) and symbolic constants.
Literal Constants BASIC has two kinds of literal constants: string and numeric. A string constant is a sequence of up to 32,767 alphanumeric characters enclosed by double quotation marks. These alphanumeric characters can be any of the characters (except the double quote character (") and carriage-return line-feed sequences) whose ASCII codes fall within the range of 1–255. This range includes both the actual ASCII characters (1–127) and the extended characters (128–255). The following are valid string constants: "HELLO" "$25,000.000" "Number of Employees"
Also, any expression consisting only of other string constants, for example: "HE" + "LLO"
Numeric constants are positive or negative integer numbers, consisting of one or more decimal digits (0–9), with a negative sign prefix (-) for negative numbers. The range for integer decimal constants is -32768 to 32767. Note: Numeric constants in BASIC cannot contain commas. For example: 68 407 -1 29000
Chapter 2 Data Types 9
Page 18
Symbolic Constants BASIC provides symbolic constants that can be used in place of numeric or string values. The following fragment declares two symbolic constants and uses one to dimension an array: CONST MAXCHAR%=254, MAXBUF%=MAXCHAR%+1 DIM Buffer% (MAXBUF%)
The name of a symbolic constant follows the same rules as a BASIC variable name. You may include a type-declaration character (% or $) in the name to indicate its type, but this character is not part of the name. For example, after the following declaration, the names N$ and N% cannot be used for variable names because they have the same name as the constant: CONST N=45
A constant’s type is determined by an explicit type-declaration character or assumed to be an integer.
Variables A variable is a name that refers to an object - a particular number or string. Simple variables refer to a single number or string. Array variables refer to a group of objects of the same type. A numeric variable, whether simple or array, can only be assigned an integer numeric value; a string variable can only be assigned a characterstring value. The variable must always match the type of data (numeric or string) assigned to it. Variables can be assigned to a constant value: A = 4 B$ = "sail the ocean blue "
Variables can also be assigned the value of another string or numeric variable: A$ = B$ Profits = NetEarnings 10
Chapter 2 Data Types
Page 19
Before a variable is assigned a value, its value is undefined. No assumptions should be made about the value of a variable until it has been explicitly assigned a value. See Chapter 3, “Expressions and Operators,” for more information on the operators used in BASIC for combining variables and constants.
Variable Names A BASIC variable name may contain any number of characters. The characters allowed in a variable name are letters, numbers, the underscore character, and the type-declaration characters (% and $). Variable names are not case sensitive in BASIC. The first character in a variable name must be a letter. See the section “Simple Variables” on page 12. A variable name cannot be a reserved word, but embedded reserved words are allowed. For example, the following statement is illegal because SEEK is a reserved word (BASIC is not case sensitive): Seek = 8
However, the following statement is legal, since the reserved word is embedded within the variable name: TimeSeek = 8
Reserved words include all BASIC commands, statements, function names, and operator names. See Appendix A for a complete list of BASIC reserved words.
Chapter 2 Data Types 11
Page 20
Variable Types This section discusses the two variable types: simple variables (variables referring to a single object) and array variables (variables referring to a group of objects). Simple Variables Simple variables can be numeric or string variables. You can specify simple variable types by one of two ways: •= 1. Append one of the following type-declaration suffixes to the variable name: $
(for string variables)
%
(for integer variables)
The dollar sign ($) is the type-declaration character for string variables; it declares that the variable represents a string. You can assign a string constant of up to 31 characters to it by default, as in the following example: A$ = "SALES REPORT"
The percent sign (%) is the type-declaration suffix for numeric variables; it declares that the variable represents an integer number. Variables without a type-declaration suffix are assumed to be integer variables. •= 2. Declare the variable in a DIM statement having the form: DIM variablename For example, the following statement declares the variable A as being a string type: DIM A$
12
Chapter 2 Data Types