INC        Increment a variable by one

Top  Previous  Next

Syntax:

INC

[ variable ]

Arguments:

[ variable ]

A variable containing from one to six numeric characters.

Options:

none

 

 

 

This script command is used to increment 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 INC (and DEC) command are assumed to be a fixed length of one to six characters and contain leading zeros. When the extent of a variable is exceeded, the value wraps (i.e., a two character string is greater than 99 after adding one then the value wraps to 00; 9 wraps to 0; 999 wraps to 000; 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 99 to 00, for example, may not be appropriate when doing simple arithmetic. The INC 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 is set equal to 000.

 

Consider the example below where a variable is used to retrieve sequentially named files (using an incrementing file extension - i.e., file.001, file.002, 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

INC counter

SET FileName = basename & counter

DISPLAY FileName

RCVFILE FileName

GOTO loop

 

In another use, consider the example below where a variable is used as a loop counter. In this case, the leading zero is required even as a loop counter in order for counter to become greater than 9.

 

SETNUM counter = 01

;; loop 20 times

:loop

DASHBOARDMSG "The current value is " + counter

PAUSE /for=1

INC counter

IFNUM< counter 20 GOTO loop

 

In this example, we discover what happens when a value more than six characters long is passed as the argument:

 

SET too_long = 0000001

CMD:        SET too_long = 0000001

INC too_long

CMD:        INC too_long

*Invalid argument(s). [1100]

 

 

Related command(s): DEC, IFNUM, SETNUM, SET