The ARG.COUNT() function returns the number of arguments passed into the current subroutine. It is intended for use with subroutines declared with the VAR.ARGS option.
When a program calls a subroutine that has been declared with the VAR.ARGS option, the actual number of arguments passed may be fewer than the number of argument variables in the subroutine definition. The unused argument variables will be left unassigned. The ARG.COUNT() function allows a subroutine to determine the number of arguments that have been passed. See the ARG() function for a way to access arguments by their position in the argument list.
When used in a function, the value returned by ARG.COUNT() excludes the hidden return argument.
Note that the ARG.COUNT() function relates to the arguments passed into a SUBROUTINE, FUNCTION or CLASS module and does not reflect the number of arguments passed into a local subroutine or function.
FUNCTION AVG(A,B,C,D,E) VAR.ARGS
TOTAL = 0
FOR I = 1 TO ARG.COUNT()
TOTAL += ARG(I)
RETURN TOTAL / ARG.COUNT()
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.