num_args()

 

NUM_ARGS( ) takes no arguments.  It returns an integer that corresponds to the number of command-line arguments that followed the name of your 4GL program when the user invoked it.

 

Usage

 

The built-in NUM_ARGS( ) function, and that of ARG_VAL( ), can pass data to a compiled 4GL program from the command line that invoked the program.

For example, suppose that the 4GL program called program_arguments can accept one or more account names as command-line arguments (such as, to process account reports). 

 

program_arguments St MegaSoft01 Querix02 Provia03

 

In either case, statements in the following program fragment use the ARG_VAL( ) function to store in an array of CHAR variables all the names that the user who invoked program_arguments entered as command-line arguments:

 

MAIN

  DEFINE

    args ARRAY[8] OF CHAR(10),

    i, line_disp SMALLINT,

    str_disp char(50)                         

  FOR i = 1 TO NUM_ARGS()

    LET args[i] = ARG_VAL(i)

  END FOR

LET str_disp = "Total Number of passed arguments: ", NUM_ARGS()

  DISPLAY str_disp at 2, 5

  FOR i = 1 TO NUM_ARGS()

    LET line_disp = i + 5

    LET str_disp = "Argument " , i,  " was ", args[i]

    DISPLAY str_disp at line_disp , 5

  END FOR

 call fgl_getkey()

END MAIN

 

After program_arguments is invoked by these command-line arguments, the NUM_ARGS( ) function returns the value 3. Executing the LET statements in the FOR loop assigns the following values to elements of the args array.

 

Variable

Value

args(1)

Megasoft01

args(2)

Querix01

args(3)

Provia01

 

 

Reference:

ARG_VAL( )