Function PValue() Foundation

Determines or changes the value of an argument passed as a parameter.

PValue( <nParamIndex> [,<xValue>] ) --> xParamValue
<nParamIndex> is a positive integer indicating the ordinal position of the argument in the parameter list for the function, procedure, or method.
<xValue> is optional and specifies a value to assign to the parameter at the ordinal position <nParamIndex>.

The return value of PValue() is the value of the argument passed to the function, procedure, or method at the ordinal position <nParamIndex>. If <xValue> is specified, this value is the return value (analogous to an assignment).


The function PValue() allows values of the arguments passed to a function, method, or procedure to be determined. It is often used with the function PCount() which determines the number of passed arguments. Both functions work with the actual arguments passed and not with the number of formal parameters declared.

Formal parameters are declared in the declaration of a function, procedure, or method. When the function, procedure, or method is called, arguments are passed to it. The number of arguments may not match the number of formal parameters. The functions PCount() and PValue() are often used in functions, procedures, or methods when the actual number of arguments is not known.

The function PValue() cannot be called in a code block, but only in the context of functions, procedures, and methods.

Call a function with various numbers of arguments

// The example illustrates the use of the function PValue() 
// using the UDF Average(). This function has no formal 
// parameter list, but adds all passed arguments using 
// PValue() in a FOR..NEXT loop. Then the result is 
// divided by the number of passed arguments 


   ? Average( 10, 20 )                  // result: 15.00 
   ? Average( 1,2,3,4,5,6,7,8,9,10 )    // result: 5.50 


FUNCTION Average() 
   LOCAL nSum := 0, i, imax 

   imax := PCount()                 // number of passed arguments 

   FOR i:=1 TO imax                 // sum data 
      nSum += PValue( i ) 

RETURN ( nSum / imax ) 


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.