4D v16.3

Count parameters

Home

 
4D v16.3
Count parameters

Count parameters 


 

Count parameters -> Function result 
Parameter Type   Description
Function result  Longint in Number of parameters actually passed

The Count parameters command 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 this command is associated with a menu, it returns 0.

4D 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` Displays text message and appends it to $wrArea
 APPEND TEXT(vtSomeText;0;$vhDocRef` Displays text message and writes it to $vhDocRef

4D 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

 
PROPERTIES 

Product: 4D
Theme: Language
Number: 259

This command can be run in preemptive processes

 
HISTORY 

Created: < 4D v6

 
ARTICLE USAGE

4D Language Reference ( 4D v16)
4D Language Reference ( 4D v16.1)
4D Language Reference ( 4D v16.2)
4D Language Reference ( 4D v16.3)