Browse
(440) 299-7778
Menu
(440) 299-7778
One-year parts and labor warranty30-day money-back guaranteeEnglishEspañolContact

The text of a manual · part 3 of 26

Videx BASIC for DuraTrax, LaserLite, LaserLite Pro, and LaserLite Mx Data Collectors, pages 21 to 30

Pages 21 to 30 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 21

Array Variables An array is a group of objects that are referenced with the same variable name. The individual values in an array are called elements. These elements are the array variables, and they can be used in nearly any BASIC statement or function that uses variables. An array is “dimensioned” when you declare the name, type, and number of elements in the array. Each array element is referred to by an array variable subscripted with an integer or an integer expression. The maximum subscript value is set with the DIM statement. (See page 78–79 for more information on the DIM statement.) You may have arrays of any variable type. Array elements require a certain amount of memory, depending on the variable type. To find the approximate amount of memory required by an array, multiply the number of elements by the bytes per element required for the array type. For example, consider the following two arrays: DIM Array1$ (7) * 12 DIM Array2% (99)

The first array, Array1, has 8 (0–7) string elements that can have up to 12 characters each, so Array1 takes approximately 96 (8 x 12) bytes of memory. The second array, Array2, has 100 (0–99) 2-byte integer elements so Array2 takes approximately 200 (100 x 2) bytes of memory.

Chapter 2 Data Types 13

Page 22

Videx BASIC Memory Considerations Videx BASIC supports up to 32K of data. Data includes all simple variables, arrays, and constants declared in the program. It also includes the name of the data file if it is a constant in the program. For example, the following program line: open "test.crf" for reference as #1 has two constants: "test.crf" and 1. The 32K data limit does not include run-time memory limitations, such as file tables, data storage, or cross-reference files. Videx BASIC also additionally supports up to 32K of code. Code is the set of instructions to the BASIC engine in the DuraTrax, LaserLite, LaserLite Pro, or LaserLite Mx operating system.

14

Chapter 2 Data Types

Page 23

Chapter 3 Expressions & Operators This chapter discusses how to combine, modify, compare, or get information about expressions by using the operators available in BASIC. Anytime you do a calculation or manipulate a string, you are using expressions and operators. This chapter describes how expressions are formed, discusses the order in which BASIC uses operators, and concludes by describing the following four kinds of operators: Arithmetic, Comparison, Bitwise, and String.

Expressions and Operators An expression can be a string or numeric constant, a variable, or a single value obtained by combining constants, variables, and other expressions with operators. Operators perform mathematical or logical operations on values. The operators provided by Videx BASIC can be divided into four categories, as follows: 1. Arithmetic operators perform calculations. See page 17 for information. 2. Comparison operators compare strings and numeric values. See page 19 for information. 3. Bitwise operators test complex conditions or manipulate individual bits. See pages 20–21 for information. 4. String operators combine and compare strings. See pages 22–23 for information.

Chapter 3 Expressions & Operators

15

Page 24

Hierarchy of Operations The BASIC operators have an order of precedence. Operations are executed in the following order: 1. Negation ( - ) and NOT (bitwise complement). 2. Multiplication ( * ), division ( / ), and modulo arithmetic (MOD). 3. Addition ( + ), subtraction ( - ), AND (bitwise conjunction), and OR (bitwise disjunction). 4. Comparison operations (=, >, <, <>, <=, >=). Note: Operator precedence is somewhat different in Videx BASIC than in QuickBASIC; when in doubt, use parentheses. If the operations are different and of the same level, the leftmost one is executed first, the rightmost last, as shown below: A = 3 + 12 / 6 * 3 - 2

'A = 7

The order of operations would be as follows: 1. 2. 3. 4.

12 / 6 2*3 3+6 9-2

(= 2) (= 6) (= 9) (= 7)

In a series of additions or multiplications, there is a fixed evaluation order, beginning with the first and preceding to the right. For example, in the following example: B = 3 + 12 + 6 + 3 + 2

'B = 26

The order of operations would be as follows: 1. 2. 3. 4. 16

3 + 12 (= 15) 15 + 6 (= 21) 21 + 3 (= 24) 24 + 2 (= 26)

Chapter 3 Expressions & Operators

Page 25

Arithmetic Operators You can change the order in which the arithmetic operations are performed by using parentheses. Operations within parentheses are performed first. Inside parentheses, the usual order of operation is maintained. Here are some sample algebraic expressions and their BASIC counterparts: Algebraic Expression

BASIC Expression

X−Y Z

(X − Y) Z

XY Z

X ∗Y Z

X+Y Z

(X + Y) Z

X (−Y )

X ∗ (−Y ) or X ∗−Y

Chapter 3 Expressions & Operators

17

Page 26

Modulo Arithmetic Modulo arithmetic is denoted by the modulus operator MOD. Modulo arithmetic provides the remainder of an integer division, rather than the quotient. For example: 16 MOD 5: 16 ÷ 5 = 3 with a remainder of 1 Result = 1 3250 MOD 256: 3250 ÷ 256 = 12 with a remainder of 178 Result = 178 10 MOD 4: 10 ÷ 4 = 2 with a remainder of 2 Result = 2 68 MOD 8: 68 ÷ 8 = 8 with a remainder of 4 Result = 4 See LOF function, SEEK function, and TOUCH statement in Chapter 3 to see examples of how MOD is used. • Examples: PRINT 10 MOD 4

‘Prints the remainder of 10 ÷ 4

PRINT 26 MOD 5

‘Prints the remainder of 26 ÷ 5

PRINT 68 MOD 8

‘Prints the remainder of 68 ÷ 8

• Output: 2 1 4

18

Chapter 3 Expressions & Operators

Page 27

Comparison Operators Comparison operators are used to compare two values, as shown in the following table. They work on both integers and strings. The result of the comparison is either true (nonzero) or false (zero). This result can then be used to make a decision regarding program flow. (Strings are compared lexicographically; see pages 22–23 for information on string comparisons.)

Comparison Operators and Their Functions Operator

Relation Tested

Expression

=

Equality*

X=Y

<>

Inequality

X <> Y

<

Less than

X<Y

>

Greater than

X>Y

<=

Less than or equal to

X <= Y

>=

Greater than or equal to

X >= Y

* The equal sign is also used to assign a value to a variable.

When arithmetic and comparison operators are combined in one expression, the arithmetic operations are always done first. For example, the following expression is true if the value of X + Y is less than the value of (T - 1)/Z: X + Y < (T - 1)/Z

Chapter 3 Expressions & Operators

19

Page 28

Bitwise Operators Bitwise operators perform tests on multiple relations, bit manipulations, or Boolean operations; they return a true (nonzero) or false (zero) value to be used in making a decision. Example: IF (D < 200) AND (F < 4) THEN WHILE (I > 10) OR (K < 0) . . .

WEND IF NOT P THEN PRINT "Name not found"

There are three bitwise operators in Videx BASIC: NOT, AND, and OR. They are described in the following table. Videx BASIC Bitwise Operators Operator NOT AND OR

Meaning Bitwise complement Bitwise conjunction Bitwise disjunction (inclusive “or”)

Each operator returns results as indicated in the following table. A T indicates a true value (nonzero) and an F indicates a false value (zero). Values Returned by Bitwise Operations Values of X Y

T T F F

T F T F

Value Returned by Bitwise Operator X X NOT AND OR X Y Y F T T F F T T F T T F F

Bitwise operators compare each bit of the first operand with the corresponding bit in the second operand to compute the bit in the result. 20

Chapter 3 Expressions & Operators

Page 29

In these bitwise comparisons, a 0 bit is equivalent to a false value (F) in the previous table, while a 1 bit is equivalent to a true value (T). It is possible to use bitwise operators to test bytes for a particular bit pattern. For example, the AND operator can be used to mask all but one of the bits of a status byte, while the OR operator can be used to merge two bytes to create a particular binary value. • Examples: PRINT 63 AND 16 PRINT -1 AND 8 PRINT 10 OR 9 PRINT NOT 10, NOT 11, NOT 0

'NOT X = -(X + 1)

• Output: 16 8 11 -11

-12

-1

The first PRINT statement uses AND to combine 63 (111111 binary) and 16 (10000). When BASIC calculates the result of an AND it combines the numbers bit by bit, producing a 1 only when both bits are 1. Because the only bit that is a 1 in both numbers is the fifth bit, only the fifth bit in the result is a 1. The result is 16 or 10000 binary. In the second PRINT statement, the numbers -1 (1111111111111111 binary) and 8 (1000 binary) are combined using another AND operation. The only bit that is a 1 in both the numbers is the fourth bit, so the result is 8 decimal or 1000 binary. The third PRINT statement uses an OR to combine 10 (binary 1010) and 9 (binary 1001). An OR produces a 1 bit whenever either bit is a 1, so the result of the OR in the third PRINT is 11 (binary 1011). Performing a NOT on a number, as in the fourth PRINT statement, changes all one bits to zeros and all zero bits to ones. Because of the way two’s complement numbers work, taking the NOT of a value is the same as adding 1 to the number and then negating the number. So in the final PRINT statement, the expression NOT 10 gives a result of -11, NOT 11 gives a result of -12, and NOT 0 gives a result of -1. Chapter 3 Expressions & Operators

21

Page 30

String Operators A string expression consists of string constants, string variables, and other string expressions combined by string operators. There are two classes of string operations: concatenation and string comparison. Concatenation is the act of combining two strings. The plus sign (+) is the concatenation operator for strings. For example, the following program fragment combines the strings CHR$(13) and CHR$(10) to create a carriage return/line feed combination for use in a PRINT statement. Note: CHR$(13) represents a carriage return and CHR$(10) represents a line feed. The following program also combines variables A$ and B$ to produce the value FILENAME. A$ = "FILE" : B$ = "NAME" NL$ = CHR(13) + CHR$ (10) AB$ = A$ + B$ PRINT AB$; NL$; "NEW ";AB$

• The output is:

FILENAME NEW FILENAME

Strings can be compared using the following comparison operators: Operator <> = < > <= >=

Description Not equal to Equal to Less than Greater than Less than or equal to Greater than or equal to

Note: These are the same relational operators used with numbers. String comparisons are made by taking corresponding characters from each string and comparing their ASCII codes. If the ASCII codes are the same for all the characters in both strings, the strings are equal.

22

Chapter 3 Expressions & Operators