Command COUNT Foundation

Determines the number of records matching a condition.

Syntax
COUNT TO <VarName> ;
  [FOR   <lForCondition>] ;
  [WHILE <lWhileCondition>] ;
  [NEXT  <nCount>] ;
  [REST] ;
  [ALL]
Parameters
<VarName>
The result of the command COUNT is assigned to the variable <VarName>. If the variable does not exist, it is created as a PRIVATE variable.
<lForCondition>
<lForCondition> is an optional logical expression defining a condition. A record is counted only if <lForCondition> returns the value .T. (true).
<lWhileCondition>
<lWhileCondition> is an optional logical expression defining a condition. The counting of the records is terminated as soon as the expression returns the value .F. (false).
<nCount>
<nCount> specifies the number of records to be considered during counting, starting with the current record.
REST
The option REST determines whether records are to be considered only from the current record to the last record. If a condition is specified, the option ALL is the default value.
ALL
The option ALL specifies that all records are considered. If a condition is specified, the condition is tested for all records.
Description

The command COUNT counts the number of records in the current work area matching the specified condition. The count range can be limited by options such as NEXT or REST. The count result is assigned to the variable <VarName>.

Examples
COUNT
// In the example, the unpaid invoices in an 
// invoice file are counted. 

PROCEDURE Main 
   LOCAL nUnPaid := 0 

   USE Invoice NEW 

   COUNT TO nUnPaid FOR Payment == 0 

   ? "Unpaid invoices:", nUnPaid 

   USE 
RETURN 
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.