Hardware manual

Impact Reference Guide Constants
5-3 Datalogic Automation Inc.
TIP: If the variable’s name has a specific ending, the type will be assigned automatically. Variables ending in
"real" are assigned type Real, "string" are assigned type String, and "int" are assigned type Integer. For
example, count_real is a Real, name_string is a String, and count_int is an Integer.
Examples of valid variable names:
myvariable
_variablename
count_real
variable$
Examples of invalid variable names:
chr$ (this is a reserved word)
variable name (contains a space)
variable:name (cannot use a colon inside the name)
my_variable: (colon as the final character is a GOTO label name)
Constants
Constants retain the same value throughout the program and cannot be changed. This allows you to keep
constants in one place so they can be easily changed, if necessary. You can create constants by assigning a
value to a variable. Example:
constant_name = value
const percent = 0.15
tax = purchase * percent
Undefined (undef)
Impact Basic uses a special constant named "undef." This constant is undefined in the sense that it has no
value (it is not zero or false and it is not any data type). Array elements that have no value assigned to them
are undef. If any variables in a mathematical operation are undef, the result of the operation is undef.
Some built-in functions return undef if the operation fails. For example, the function INSTR will return
undef if the search string is not found.
If a function’s definition indicates that it may return undef, you should include a check for that value in your
code. For example:
location_int = INSTR ("basestring","ase",1)
IF location_int = undef then
msg_string = "The string was not found"
ELSE
msg_string="The string was found"
ENDIF
You can also call the function undef to assign the value "undef" to a variable. This example assigns the unde-
fined value to all elements in the array "mylist." Example:
undef mylist
If a divide by zero operation is performed, the result is "undef" which is displayed as a value of zero in the
variable’s property.
To make the Basic tool abort with an error on a divide by zero operation, add this code to the tool:
Option RaiseMathError 1