version 3
Count parameters Number
| Parameter | Type | Description | ||||
| This command does not require any parameters | ||||||
| Function result | Number | Number of parameters actually passed | ||||
Description
The command Count parameters returns the number of parameters passed to a project method.
WARNING: Count parameters is meaningful only in a project method that has been called by another method (project method or other). If the project method calling Count parameters is associated with a menu, Count parameters returns 0.
Examples
1. 4th Dimension project methods accept optional parameters, starting from the right.
For example, you can call the method MyMethod(a;b;c;d) in the following ways:
MyMethod ( a ; b ; c ; d ) ` All parameters are passed MyMethod ( a ; b ; c ) ` The last parameter is not passed MyMethod ( a ; b ) ` The last two parameters are not passed MyMethod ( a ) ` Only the first parameter is passed MyMethod ` No Parameter is passed at all
Using Count parameters from within MyMethod, you can detect the actual number of parameters and perform different operations depending on what you have received. The following example displays a text message and can insert the text into a 4D Write area or send the text into a document on disk:
` APPEND TEXT Project Method
` APPEND TEXT ( Text { ; Long { ; Time } } )
` APPEND TEXT ( Text { ; 4D Write Area { ; DocRef } } )
C_TEXT ($1)
C_TIME ($2)
C_LONGINT ($3)
MESSAGE ($1)
If (Count parameters>=3)
SEND PACKET ($3;$1)
Else
If (Count parameters>=2)
WR INSERT TEXT ($2;$1)
End if
End if
After this project method has been added to your application, you can write:
APPEND TEXT (vtSomeText) ` Will only display the text message APPEND TEXT (vtSomeText;$wrArea) ` Will display the text message and append it to $wrArea APPEND TEXT (vtSomeText;0;$vhDocRef) ` Will display the text message and write it to $vhDocRef
2. 4th Dimension project methods accept a variable number of parameters of the same type, starting from the right. To declare these parameters, you use a compiler directive to which you pass ${N} as a variable, where N specifies the first parameter. Using Count parameters you can address those parameters with a For loop and the parameter indirection syntax. This example is a function that returns the greatest number received as parameter:
` Max of Project Method
` Max of ( Real { ; Real2... ; RealN } ) -> Real
` Max of ( Value { ; Value2... ; ValueN } ) -> Greatest value
C_REAL ($0;${1}) ` All parameters will be of type REAL as well as the function result
$0:=${1}
For ($vlParam;2;Count parameters)
If (${$vlParam}>$0)
$0:=${$vlParam}
End if
End for
After this project method has been added to your application, you can write:
vrResult:=Max of (Records in set("Operation A");Records in set("Operation B"))
or:
vrResult:=Max of (r1;r2;r3;r4;r5;r6)
See Also
Compiler commands, C_BLOB, C_BOOLEAN, C_DATE, C_GRAPH, C_INTEGER, C_LONGINT, C_PICTURE, C_POINTER, C_REAL, C_STRING, C_TEXT, C_TIME.