ARGCOUNT numberOfArguments

Used inside a subroutine, ARGCOUNT puts the number of optional arguments that the subroutine was invoked with into the numberOfArguments variable. Optional arguments are defined by NEWCMD , which introduces them with the '#' mark. The returned argument count does not include a count of the dummy arguments.

ARGCOUNT may not be used outside of a subroutine.

See also: GETARG and NEWCMD

The following subroutine can accept any number of optional arguments. It uses ARGCOUNT to find how many optional arguments are in the invocation.

'Subroutine to do an ascending coordinated sort, in place, of two or more vectors
'based on the first vector (keyVec) as the key. All vectors must be the same length.
NEWCMD SORTCOORD keyVariable #"variable {variable}"  ?"Coordinated sort, in place, of two or more vectors"
   ARGCOUNT numberOfArgs
   IF numberOfArgs > 0
      TAGSORT keyVariable tags
      TAKE keyVariable tags keyVariable
      FOREACH argNum 1,numberOfArgs
         GETARG argNum arg
         TAKE arg tags arg
      DEBUG "ERROR: Incorrect number of arguments in SORTCOORD."

Here is an example invoking SORTCOORD with three arguments:

NAME male female
DATA (62   68  73 58  66) height
DATA (120 165 198 99 115) weight
DATA (female male male female female) sex

SORTCOORD height weight sex
PRINT height weight sex


height: (58.0 62.0 66.0 68.0 73.0)
weight: (99.0 120.0 115.0 165.0 198.0)
sex: (female female female male male)