Page 2 of 2

Re: Counter in report (revisited).

PostPosted: Fri Feb 11, 2011 5:06 pm
by nageswaragunupudi
1. In case I have to count records in a report that is working with the bFor data, how can I do it ?

local nCounter := 1

COLUMN DATA nCounter HEADER "Number" PICTURE '999'

FOR cond -> { || If( <yourforcond>, ( nCounter++, .t. ), .f. ) }

2. hen I have to build filters at runtime, what's the best way to do it ?

You are anyway constructing a for condition using field names of the DBF. Please set the same string as SET FILTER TO &focond

Whether the filter is fully optimized for speed or not depends on whether you have indexes built on the fields used in the condition.

Re: Counter in report (revisited).

PostPosted: Fri Feb 11, 2011 5:20 pm
by HunterEC
Rao:

Thank you very much.

Re: Counter in report (revisited).

PostPosted: Fri Feb 11, 2011 6:04 pm
by HunterEC
Rao:
The code works perfectly but each page total is one value higher than the correct total. Here's the code:
Code: Select all  Expand view
#include 'fivewin.ch'
#include 'report.ch'

REQUEST DBFCDX

function Main()

   local cAlias, oWnd

   if ( cAlias := OpenData() ) != nil
      DEFINE WINDOW oWnd
      ACTIVATE WINDOW oWnd HIDDEN ;
         ON INIT ( ( cAlias )->( Report() ), oWnd:End() )
   endif

   ( cAlias )->( DbCloseArea() )

return nil

function Report()

   local oRep, oFont
   local cAlias   := Alias(), nCounter := 0

   DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-9

   REPORT oRep FONT oFont PREVIEW

        COLUMN DATA nCounter TITLE "Number" PICTURE '9999'  TOTAL
      COLUMN TITLE "UNIT" DATA 1 PICTURE "999" TOTAL
      COLUMN TITLE "First" DATA ( cAlias )->FIRST SIZE 20
      COLUMN TITLE "State" DATA ( cAlias )->STATE SIZE 5
      COLUMN TITLE "Age" DATA ( cAlias )->AGE ;
         PICTURE "9999" RIGHT
      COLUMN TITLE "Salary" DATA ( cAlias )->SALARY ;
         PICTURE "99,999,999.99" RIGHT  TOTAL

   ENDREPORT

    oRep:bFor := { || If(( cAlias )->SALARY > 25000 , (nCounter++, .t. ), .f. ) }
   ACTIVATE REPORT oRep ;
      ON ENDPAGE ( oRep:aColumns[ 1 ]:nTotal := nCounter )


RELEASE FONT oFont

return nil

static function OpenData()

   local cAlias, lOpen := .f.

   cAlias := cGetNewAlias( "CUST" )
   USE E:\Comp\FWH\samples\customer.dbf ;
      NEW ALIAS (cAlias) SHARED VIA 'DBFCDX'

   lOpen := Select( cAlias ) > 0

return If( lOpen, cAlias, '' )
 


Thank you.

Re: Counter in report (revisited).

PostPosted: Sun Feb 13, 2011 7:30 am
by James Bott
Try subtracting 1 here:

ON ENDPAGE ( oRep:aColumns[ 1 ]:nTotal := nCounter - 1 )