DEC        Decrement a variable by one

Top  Previous  Next

Syntax:

DEC

[ variable ]

Arguments:

[ variable ]

A variable containing from one to six numeric characters.

Options:

None

 

 

 

This script command is used to decrement a variable by one. If each character in the variable is not numeric (e.g., digits 0 - 9), then the command fails.

 

Numeric strings used in the DEC (and INC) command are assumed to be a fixed length of one to six characters and contain leading zeros. When the value of a variable goes negative, the value wraps (i.e., a two character string is less than 00 after subtracting one then the value is set to 99; 0 wraps to 9; 000 wraps to 999; etc.)

 

Caution

This command is primarily intended to provide a mechanism for sequentially naming files, not as a simple numeric function. So its behavior of wrapping from 00 to 99, for example, may not be appropriate when doing simple arithmetic. The DEC command may be used for both purposes but you need to remain aware of the command’s behavior.

 

If the variable is not previously assigned, the variable is created and set equal to 000.

 

Consider the example below where a variable is used to retrieve sequentially named files (using an decrementing file extension - i.e., file.999, file.998, etc.) from an FTP site. Note: numeric values should be assigned enclosed in quotation marks when strings with leading zeroes are desired.

 

SET basename = "file."

SETNUM counter = "000"

:loop

DEC counter

SET file name = basename & counter

DISPLAY file name

RCVFILE file name

GOTO loop

 

In another use, consider the example below where a variable is used as a decrementing loop counter.

 

SETNUM counter = 10

;; loop 10 times

:loop

DISPLAY counter

DEC counter

IFNUM! counter 0 goto loop

 

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