ARG()

ARG()

Top  Previous  Next

 

The ARG() function returns and argument value based on its position in the argument list. It is intended for use with subroutines declared with the VAR.ARGS option.

 

 

Format

 

ARG(n)

 

where

 

nis the argument list position, numbered from one.

 

 

Subroutines declared with the VAR.ARGS option may have a variable number of arguments. Although each argument must have a name assigned to it in the SUBROUTINE statement, it is often useful to be able to process a series of arguments by indexing this list.

 

The ARG() function returns the value of argument n. The actual number of arguments passed may be determined using the ARG.COUNT() function. Use of an argument position value less than one or greater than the number of arguments causes the program to abort.

 

 

Example

 

FUNCTION AVG(A,B,C,D,E) VAR.ARGS

  TOTAL = 0

  FOR I = 1 TO ARG.COUNT()

     TOTAL += ARG(I)

  NEXT I

  RETURN TOTAL / ARG.COUNT()

END

 

The above function returns the average of the supplied arguments. Because this function is declared with the VAR.ARGS option, the ARG.COUNT() function is used to determine the actual number of arguments and the ARG() function is used to access each argument by its position.

 

 

See also:

ARG.COUNT(), ARG.PRESENT(), SET.ARG