Page 1 of 2

nCounter Report not run ok RESOLVED

Posted: Thu Oct 08, 2020 9:16 am
by Silvio.Falconi
Dear Antonio,

if I made

GROUP ON CU->STATE ;
FOOTER " » Total FOR STATE » "+::oReport:aGroups[1]:cValue +"("+ltrim(str(::oReport:aGroups[1]:nCounter))+")" ;
FONT 1

oReport:nCounter is right for each group and the total counter is right


If I not use Groups but only easy bfor sample :

ACTIVATE REPORT oReport FOR dInicio <= CU->HIREDATE .AND. CU->HIREDATE <= dFinal ;
ON END ( oReport:StartLine(), oReport:EndLine(), oReport:StartLine(), ;
oReport:Say(1, 'Total customers: '+Tran(oReport:nCounter, '@E 999,999'), 1),;
oReport:EndLine() )

give me bad nCounter

SO IFI wish print only the hiredate from 01/01/1990 to 01/011991

execute the codeblock bfor ( FOR dInicio <= CU->HIREDATE .AND. CU->HIREDATE <= dFinal ) because it print only 57 records
then print on say "total customers " 500

Image

why ?



here the test (rep21.prg)

Code: Select all


#include "FiveWin.ch"
#include "report.ch"

request DBFCDX

STATIC oReport

Function Rep21()

     LOCAL oFont1, oFont2, oFont3, oPen1, oPen2

     local dInicio :=ctod("01/01/1990")
     local dFinal  :=ctod("01/01/1991")


     DEFINE FONT oFont1 NAME "ARIAL" SIZE 0,-10
     DEFINE FONT oFont2 NAME "ARIAL" SIZE 0,-10 BOLD
     DEFINE FONT oFont3 NAME "ARIAL" SIZE 0,-10 BOLD ITALIC

     DEFINE PEN oPen1 WIDTH 3
     DEFINE PEN oPen2 WIDTH 1

     USE CUSTOMER NEW VIA "DBFCDX" ALIAS CU
  //  index on cu->state tag 1 temporary
      CU->(DbGoTop())

     REPORT oReport ;
          TITLE  "*** FiveWin Report DEMO ***",;
                 "",;
                 OemtoAnsi("by FiveTech"),;
                 "" ;
          FONT   oFont1,;
                 oFont2,;
                 oFont3 ;
          PEN    oPen1,;
                 oPen2 ;
          HEADER "Date: "+dtoc(date()),;
                 "Time:  "+time() ;
                 RIGHT ;
          FOOTER OemtoAnsi("Page: ")+str(oReport:nPage,3) ;
                 CENTERED ;
          PREVIEW

    /*  
                 //FOR TEST a GROUP
 GROUP ON CU->State ;
           FOOTER "Total State "+oReport:aGroups[1]:cValue+ ;
                  " ("+ltrim(str(oReport:aGroups[1]:nCounter))+")" ;
           FONT 2
      */
     COLUMN TITLE "ST" ;
          DATA CU->State ;
          FONT 2  ;
          GRID 2

     COLUMN TITLE "City" ;
          DATA CU->City ;
          GRID 2

     COLUMN TITLE "First Name","Last Name" ;
          DATA CU->First , CU->Last ;
          GRID 2

     COLUMN TITLE "   Salary" ;
          DATA CU->Salary ;
          PICTURE "9,999,999" ;
          SIZE 9 ;
          TOTAL ;
          SHADOW ;
          GRID

     END REPORT

     IF oReport:lCreated

          /*
          First line of title bold
          */

          oReport:oTitle:aFont[1] := {|| 2 }

          /*
          Total descriptors
          */

          oReport:cGrandTotal := "Grand Total..."
          oReport:cPageTotal := "Page Total..."

          /*
          Italic when salary greater than 100,000
          */

          oReport:aColumns[4]:bDataFont := {|| iif(CU->Salary>100000,3 ,1 ) }


     ENDIF

     ACTIVATE REPORT oReport FOR dInicio <= CU->HIREDATE .AND. CU->HIREDATE <= dFinal  ;
       ON STARTGROUP oReport:NewLine() ;
             ON END ( oReport:StartLine(), oReport:EndLine(), oReport:StartLine(), ;
                     oReport:Say(1, 'Total customers: '+Tran(oReport:nCounter, '@E 999,999'), 1),;
                     oReport:EndLine() )


     /*
     Close and release
     */

     oFont1:End()
     oFont2:End()
     oFont3:End()
     oPen1:End()
     oPen2:End()

     CLOSE CU

RETURN NIL



 





IF I made ( I saw a Nages topic)

Code: Select all

 local nCounter := 1
and then

Code: Select all

oReport:bFor := { || If((dInicio <= CU->HIREDATE .AND. CU->HIREDATE <= dFinal), (nCounter++, .t. ), .f. ) }


        ACTIVATE REPORT oReport   ;
       ON STARTGROUP oReport:NewLine() ;
             ON END ( oReport:StartLine(), oReport:EndLine(), oReport:StartLine(), ;
                     oReport:Say(1, 'Total customers: '+Tran(nCounter, '@E 999,999'), 1),;
                     oReport:EndLine() )
we have 58 records but I have only 57 records , How it was possible ?

Image


TEST WITH GROUP
But when I use GRoup command with the suggestion of NAges then the total id not right

because the records ( with bfor) are allways 57 but the ncounter is 115

Image

Re: nCounter Report not run ok

Posted: Thu Oct 08, 2020 1:39 pm
by nageswaragunupudi
We will look into this

Re: nCounter Report not run ok

Posted: Thu Oct 08, 2020 3:50 pm
by FranciscoA
It seems to be an old bug.

I have tested it with version 1204, and the results are the same

Re: nCounter Report not run ok

Posted: Thu Oct 08, 2020 4:51 pm
by James Bott
This is just a guess, but it looks like it is counting report lines instead of records.

Re: nCounter Report not run ok

Posted: Thu Oct 08, 2020 5:17 pm
by artu01
Silvio.Falconi wrote:Dear Antonio,

IF I made ( I saw a Nages topic)

Code: Select all

 local nCounter := 1
and then

Code: Select all

oReport:bFor := { || If((dInicio <= CU->HIREDATE .AND. CU->HIREDATE <= dFinal), (nCounter++, .t. ), .f. ) }


        ACTIVATE REPORT oReport   ;
       ON STARTGROUP oReport:NewLine() ;
             ON END ( oReport:StartLine(), oReport:EndLine(), oReport:StartLine(), ;
                     oReport:Say(1, 'Total customers: '+Tran(nCounter, '@E 999,999'), 1),;
                     oReport:EndLine() )
we have 58 records but I have only 57 records , How it was possible ?
Silvio:
at the beginning, ncounter should be 0

Re: nCounter Report not run ok

Posted: Thu Oct 08, 2020 5:34 pm
by Silvio.Falconi
I have old exe app ( 16 bit) where the oReport:ncounter run ok also on groups, and I remember I used Ozlib where Report class was a class included
I made a research, this problem was from before perhaps 2009

For the test, If you think to found a good solution, You must try with alone , with bfor condition, and group condition

Re: nCounter Report not run ok

Posted: Thu Oct 08, 2020 6:24 pm
by Silvio.Falconi
artu01 wrote: Silvio:
at the beginning, ncounter should be 0
Dear artu01,
I have been looking for solutions for a week, turning the forum many times and all my saves from 1992 to today, from fw14.4 to the penultimate 32-bit version of 2020,
unfortunately I can't try the 16-bit exes because I have to find old 16-bit PCs and they are easy to find, but believe me I don't remember having problems with this bug

on this topic http://forums.fivetechsupport.com/viewt ... er#p110839 Mr NagesWarao explain how we must make

there is also a sample , it run for bfor condition but when you try to insert a group not run

I used his test sample and I insert group command

Code: Select all

    #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,oFont2
       local cAlias   := Alias(), nCounter := 0

       DEFINE FONT oFont NAME 'TAHOMA' SIZE 0,-9
       DEFINE FONT oFont2 NAME 'TAHOMA' SIZE 0,-10 bold

       DEFINE PEN oPen1 WIDTH 1
       DEFINE PEN oPen2 WIDTH 1


       REPORT oRep FONT oFont,oFont2;
                 PEN    oPen1,;
                 oPen2 ;
                 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


             GROUP ON ( cAlias )->STATE ;
           FOOTER space(40)+"Total State "+oRep:aGroups[1]:cValue+ ;
                  " ("+ltrim(str(oRep:aGroups[1]:nCounter))+")" ;
           FONT 2



       ENDREPORT

        oRep:bFor := { || If(( cAlias )->SALARY > 25000 , (nCounter++, .t. ), .f. ) }

        ACTIVATE REPORT oRep ;
          ON ENDPAGE ( oRep:aColumns[ 1 ]:nTotal := nCounter ) ;
           ON END ( oRep:StartLine(), oRep:EndLine(), oRep:StartLine(), ;
                     oRep:Say(1, 'Total customers: '+Tran(oRep:nCounter, '@E 999,999'), 1),;
                     oRep:EndLine() )

    RELEASE FONT oFont

    return nil

    static function OpenData()

       local cAlias, lOpen := .f.

       cAlias := cGetNewAlias( "CUST" )
       USE c:\work\FWH\samples\customer.dbf ;
          NEW ALIAS (cAlias) SHARED VIA 'DBFCDX'
         index on (cAlias)->state tag 1 temporary
       lOpen := Select( cAlias ) > 0

    return If( lOpen, cAlias, '' )
 
the condition

oRep:bFor := { || If(( cAlias )->SALARY > 25000 , (nCounter++, .t. ), .f. ) } is not execute
each total group is ok and also oRep:nCounter for each group
at the end the oRep:nCounter is 500

Re: nCounter Report not run ok

Posted: Thu Oct 08, 2020 6:43 pm
by Silvio.Falconi
James Bott wrote:This is just a guess, but it looks like it is counting report lines instead of records.
right and I think the bug is on Skip method


but now with this

Code: Select all

 
ACTIVATE REPORT oRep ;
          ON ENDPAGE ( oRep:aColumns[ 1 ]:nTotal := nCounter ) ;
           ON END ( oRep:StartLine(), oRep:EndLine(), oRep:StartLine(), ;
                     oRep:Say(1, 'Total customers: '+Tran(nCounter, '@E 999,999'), 1),;
                     oRep:EndLine() )
 
could run ok

Re: nCounter Report not run ok

Posted: Thu Oct 08, 2020 7:01 pm
by Silvio.Falconi
OK PERHAPS WE CAN RESOLVED IT

for the Group command we can use the nCounter of Report class

Code: Select all

GROUP ON ( cAlias )->STATE ;
           FOOTER space(40)+"Total State "+oRep:aGroups[1]:cValue+ ;
                  " ("+ltrim(str(oRep:aGroups[1]:nCounter))+")" ;
           FONT 2
for the other we can add on our source nCounter local variable

sample

Code: Select all

oRep:bFor := { || If((dInicio <= ( cAlias )->HIREDATE .AND. ( cAlias )->HIREDATE <= dFinal), (nCounter++, .t. ), .f. ) }

        ACTIVATE REPORT oRep ;  //  ON ENDPAGE ( oRep:aColumns[ 1 ]:nTotal := nCounter ) ;
           ON END ( oRep:StartLine(), oRep:EndLine(), oRep:StartLine(), ;
                     oRep:Say(1, 'Total customers: '+Tran(nCounter, '@E 999,999'), 1),;
                     oRep:EndLine() )
 
it seems bullshit to me but I have not found solutions

Re: nCounter Report not run ok

Posted: Thu Oct 08, 2020 10:59 pm
by cnavarro
Please, use this

Code: Select all

     oReport:bStartRecord  := { || nCounter++ }
 
Remove nCounter++ of others lines or clauses

Re: nCounter Report not run ok

Posted: Fri Oct 09, 2020 7:15 am
by Silvio.Falconi
cnavarro wrote:Please, use this

Code: Select all

     oReport:bStartRecord  := { || nCounter++ }
 
Remove nCounter++ of others lines or clauses
Error description: Error BASE/1005 Message not found: TREPORT:_BSTARTRECORD
Args:
[ 1] = O TREPORT

Stack Calls
===========
Called from: => __ERRRT_SBASE( 0 )
Called from: ../../../tobject.prg => TREPORT:ERROR( 0 )
Called from: ../../../tobject.prg => (b)HBOBJECT( 0 )
Called from: ../../../tobject.prg => TREPORT:MSGNOTFOUND( 0 )
Called from: ../../../tobject.prg => TREPORT:_BSTARTRECORD( 0 )
Called from: rep21.prg => REP21( 96 )

Re: nCounter Report not run ok

Posted: Fri Oct 09, 2020 11:45 am
by karinha

Re: nCounter Report not run ok

Posted: Fri Oct 09, 2020 11:47 am
by cnavarro
You are used

Code: Select all

     oRep:bStartRecord  := { || nCounter++ }
 
or oReport:bStartRecord ?

Re: nCounter Report not run ok

Posted: Fri Oct 09, 2020 3:47 pm
by Silvio.Falconi
cnavarro wrote:You are used

Code: Select all

     oRep:bStartRecord  := { || nCounter++ }
 
or oReport:bStartRecord ?
yes of course
but my question
for total customer we must use a local variable
for group command we need to use oRep:nCounter
Do you think about it.. is normal ?

Re: nCounter Report not run ok

Posted: Fri Oct 09, 2020 4:03 pm
by carlos vargas
Silvio..

Code: Select all

oReport:aGroups[ nGroup ]:nCounter