Function PValue() Foundation
Determines or changes the value of an argument passed as a parameter.
PValue( <nParamIndex> [,<xValue>] ) --> xParamValue
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 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
PROCEDURE Main
? Average( 10, 20 ) // result: 15.00
? Average( 1,2,3,4,5,6,7,8,9,10 ) // result: 5.50
RETURN
FUNCTION Average()
LOCAL nSum := 0, i, imax
imax := PCount() // number of passed arguments
FOR i:=1 TO imax // sum data
nSum += PValue( i )
NEXT
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.