REXX Tips & Tricks, Version 2.80


Inf-HTML [About][Toc][Index] 0.9b (c) 1995 Peter Childs


Distinguish between empty and omitted parameter



You can check if a parameter has been ommitted using the function <ARG. 
This is useful if you work with default values for parameter and if an 
empty string is a valid value for a parameter. 
(Note that this is only possible in internal or external REXX functions or 
procedures!) 
Example: 

 
/* sample code to show how to distinguish between omitted and       */
/* empty parameter                                                  */

                    /* call the subroutine with omitted and empty   */
                    /* parameter                                    */
  call TestRoutine  '', 'v2', , 'v4'

exit

/* sample sub routine                                               */
TestRoutine:
  parse arg v1, v2, v3, v4, v5

  do i = 1 to 5
    if arg( i, 'E' ) = 1 then
    do
      say 'Parameter ' || i || ' was entered. '
      say '  The value is "' || arg( i ) || '"'
    end
    else
      say 'Parameter ' || i || ' was omitted. '
  end /* do i = 1 to 4 */
return

  

Inf-HTML End Run - Successful