Variable Arithmetic and Numeric Comparisons
<< Click to Display Table of Contents >> Navigation: Robo-FTP User's Guide > Script Programming > Select Topics in Script Programming > Variable Arithmetic and Numeric Comparisons |
Robo-FTP variables are always represented internally as string values. However, numeric operations can be performed on variables and strings as long as they contain only numeric values (e.g., digits 0 - 9) or on numeric constants.
Numeric variables may be created using the SET or SETNUM command as shown below. When initializing variables, the only difference between SET and SETNUM is that SETNUM verifies that the variable is being set to a numeric value. Any previous value in the variable, regardless if it numeric or non-numeric, is discarded.
SET x = "100"
SETNUM x = 100
Numeric variables may be incremented and decremented using the INC and DEC commands as shown below.
INC x
DEC x
Basic integer arithmetic may also be performed on numeric variables using the SETNUM command. This command allows for addition, subtraction, multiplication, and division to be performed on two variables and/or numeric string constants as shown in the various statements below.
SETNUM a = 100
SETNUM x = a + a | ;; addition |
SETNUM x = a – 100 | ;; subtraction |
SETNUM x = 100 x a | ;; multiplication |
SETNUM x = a / 100 | ;; division |
Numeric variables may be compared using one of the IFNUM commands as shown below.
IFNUM= x 100 GOTO vars_equal
IFNUM< x 101 GOTO var_less_than
IFNUM> x 99 GOTO var_greater_than
IFNUM< x 101 GOTO var_less_than_or_equal
IFNUM> x 99 GOTO var_greater_than_or_equal
IFNUM!= x 99 GOTO vars_not_equal