FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Counter in report (revisited).
Posts: 10733
Joined: Sun Nov 19, 2006 05:22 AM
Re: Counter in report (revisited).
Posted: Fri Feb 11, 2011 05: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
Posts: 723
Joined: Tue Sep 04, 2007 08:45 AM
Re: Counter in report (revisited).
Posted: Fri Feb 11, 2011 05:20 PM

Rao:

Thank you very much.

Posts: 723
Joined: Tue Sep 04, 2007 08:45 AM
Re: Counter in report (revisited).
Posted: Fri Feb 11, 2011 06:04 PM
Rao:
The code works perfectly but each page total is one value higher than the correct total. Here's the code:
Code (fw): Select all Collapse
#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.
Posts: 4840
Joined: Fri Nov 18, 2005 04:52 PM
Re: Counter in report (revisited).
Posted: Sun Feb 13, 2011 07:30 AM

Try subtracting 1 here:

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

FWH 18.05/xHarbour 1.2.3/BCC7/Windows 10

Continue the discussion