Counter in report (revisited).

Re: Counter in report (revisited).

Postby nageswaragunupudi » Fri Feb 11, 2011 5:06 pm

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.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10326
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Counter in report (revisited).

Postby HunterEC » Fri Feb 11, 2011 5:20 pm

Rao:

Thank you very much.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Counter in report (revisited).

Postby HunterEC » Fri Feb 11, 2011 6:04 pm

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.
HunterEC
 
Posts: 723
Joined: Tue Sep 04, 2007 8:45 am

Re: Counter in report (revisited).

Postby James Bott » Sun Feb 13, 2011 7:30 am

Try subtracting 1 here:

ON ENDPAGE ( oRep:aColumns[ 1 ]:nTotal := nCounter - 1 )
User avatar
James Bott
 
Posts: 4840
Joined: Fri Nov 18, 2005 4:52 pm
Location: San Diego, California, USA

Previous

Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 127 guests