SETNUM        Assign or evaluate numeric variable(s)

Top  Previous  Next

Syntax:

SETNUM

[ variable ]  =  [ num1 ] [ op ] [ num2 ]

Arguments:

[ variable ]

Variable to assign; if the variable does not previously exist it is created.

 

[ num1 ]

Variable, string, or numeric constant defining the numeric value to assign to [ variable ] or the first value to evaluate arithmetically with [ value2 ] based on the numeric operator defined by [ op ].

 

[ op ]

The arithmetic operator: + (addition), - (subtaction), x (multiplication), or / (division).

 

[ num2 ]

Variable, string, or numeric constant defining the second value to evaluate arithmetically with [ value1 ] based on the numeric operator defined by [ op ].

Options:

none

 

 

 

This script command performs basic integer arithmetic on variables or strings containing numeric values (e.g., digits 0 - 9) or numeric constants, and assigns the resulting numeric value to a variable. The command results in a syntax error if either [ num1 ] or [ num2 ] are non-numeric. The SETNUM command differs from the SET command in that SET does not limit the variable to contain only numeric digits (e.g., 0 - 9).

 

Consider the following examples.

 

;; assign a numeric constant to a variable

SETNUM num = 100

 

;; assign a previously assigned variable to a variable

SETNUM num = other_num

 

;; add two variables

SETNUM num = var1 + var2

 

;; add two numeric constants

SETNUM num = 100 + 100

 

;; following syntax is equivalent

SETNUM num = "100" + "100"

 

;; add/subtract/multiply/divide constant and a variable

SETNUM num = other_num + 100

SETNUM num = othernum - 100

SETNUM num = other_num x 100

SETNUM num = other_num / 100

 

Important

The multiplication operator is ‘x’ (lower-case letter x) and not the expected ‘*’ (asterisk) character. This is because script file comments can begin with an asterisk.

 

If a numeric variable is to be used in file naming, or other string related operations, where a known string length (with leading zeroes) is desired, the SETNUM command (and INC and DEC commands) may be used as shown below.

 

;; leading zeroes are preserved when enclosed in quotes

SETNUM num = "001"

 

INC num

;; after incrementing, the result is "002"

 

DEC num

;; after decrementing, the result returns to "001"

 

Note: Leading zeroes are lost if any other arithmetic operation is performed and saved to the num variable.

 

Related Command(s):        DEC, INC, IFNUM, SET

See also:        Performing Variable Arithmetic and Numeric Comparisons