Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Mach SIx v1.1c - Reference Guide - <b>count - count records that meet a logical condition</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
  COUNT            - Count records that meet a logical condition
-------------------------------------------------------------------------------

  Syntax:

  COUNT TO <idVar> [<scope>] [WHILE <lCondition>]
           [FOR <lCondition>] [NOOPTIMIZE]

  Arguments:

  TO <idVar> identifies the variable to assign the COUNT result.  A
  variable that either does not exist or is not visible is created as a
  private variable whose scope is the current procedure.

  <scope> is the portion of the current database file to COUNT.  The
  default is ALL records.  Mach SIx only supports the ALL scope.

  WHILE <lCondition> specifies the set of records meeting the condition
  from the current record until the condition fails.  Mach SIx does not
  support the WHILE condition.

  FOR <lCondition> specifies the conditional set of records to COUNT
  within the given scope.  Mach SIx will optimize any FOR condition that
  contains one or more active index keys.

  NOOPTIMIZE, preempts optimization and forces default Clipper processing.

  Description: 

  COUNT tallies the number of records from the current work area that match
  the specified record scope and conditions.  The result is then placed in
  the specified variable.  <idVar> can be a variable of any storage class
  including a field.

  The COUNT command may be optimized by specifying one or more active index
  keys in the FOR condition.  Note that Mach SIx will only optimize a COUNT
  with a FOR condition and a scope of ALL.  WHILE conditions and alternate
  scopes cannot be optimized by Mach SIx.

  Performance Tip: 

  With SET DELETED OFF, fully optimized counts can be calculated directly
  from the active index files (no database access is required), and the
  fastest count times will be achieved.

  ---------------------------------| EXAMPLE |--------------------------------
  /*:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  *  Demonstrates an optimized COUNT command                                *
  *::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::*/

  #include "DBFSIX.CH"
  #include "MACHSIX.CH"

  LOCAL nCount := 0

  USE Account VIA "DBFSIX"  // Structural index ACCOUNT.CDX opened
                            // automatically
  CLEAR SCREEN
  ? "Example of optimized COUNT command."
  ?

  // Fully optimized count of records, taking advantage of the STATE tag
  COUNT TO nCount FOR account->STATE = "CA" .or. State = "FL"

  // Fully optimized count making use of multiple index tags
  COUNT TO nCount FOR (Age >= 20 .AND. Age < 30) .AND. ;
                  State = "AK" .and. City = "Sicily"

  // Partially optimized count of records for Orlando residents with an
  // income over 50,000 dollars.
  COUNT TO nCount FOR City = "Orlando" .AND. Income > 50000
  CLOSE ALL



Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson