Function PCount() Foundation

Determines the number of arguments passed to a function or procedure.

Syntax
PCount() --> nArgumentCount
Return

The return value of PCount() is a numeric value indicating the number of arguments passed during the call of a function or procedure (the number of arguments which the function or procedure has received). When a function or procedure has no formal parameters or when no arguments are passed, PCount() returns the value zero.

Description

PCount() returns the number of arguments passed to a function or procedure. This can be used to determine whether optional arguments at the end of the argument list are included. If only the third argument is passed to a function with three arguments, PCount() returns the value 3 and the first two arguments are initialized with the value NIL.

As an example, in the call var := TESTFUNC(,,) the value NIL is passed three times to the function TESTFUNC(). Within TESTFUNC() PCount() returns the value 3.

If arguments are missing within the argument list, their value can be compared to NIL or the data type of the arguments can be determined with the function Valtype(). Missing arguments have the value NIL and a data type identified by Valtype() == "U" (undefined).

The function PValue() is used to determine the value of a passed argument.

Examples
PCount()
// The example demonstrates the return values of PCount() 
// using a call to a user-defined function when various 
// numbers of arguments are passed. 

PROCEDURE Main 
                           **           (Value of the arguments) 
   ? UserFunc()            // result: 0 (no argument) 

   ? UserFunc( 1 )         // result: 1 (value: 1) 
   ? UserFunc(NIL)         // result: 1 (value: NIL) 

   ? UserFunc( 1,NIL)      // result: 2 (values: 1, NIL) 
   ? UserFunc(  , 2 )      // result: 2 (values: NIL, 2) 
   ? UserFunc( 1,   )      // result: 2 (values: 1, NIL) 
   ? UserFunc(  ,   )      // result: 2 (values: NIL,NIL) 
   ? UserFunc( 1, 2 )      // result: 2 (values: 1, 2 ) 

   ? UserFunc( 1, 2, 3 )   // result: 3 (values:  1 , 2 , 3 ) 
   ? UserFunc( 1,  , 3 )   // result: 3 (values:  1 ,NIL, 3 ) 
   ? UserFunc(  ,  , 3 )   // result: 3 (values: NIL,NIL, 3 ) 
   ? UserFunc(  ,  ,NIL)   // result: 3 (values: NIL,NIL,NIL) 
   ? UserFunc(  ,  ,   )   // result: 3 (values: NIL,NIL,NIL) 
RETURN 

FUNCTION UserFunc( p1, p2, p3 ) 

RETURN PCount() 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.