Home General
New Blog Posts: Merging Reports - Part 1 and Part 2

Summing values in code

edited May 2003 in General
I have a detail band with 4 regions. Which region is preinted depends on a
flag (a field in the dataset). In the BeforePrint event of the detail band I
determine which region(s) will be printed. At the end of a group I would
like to print Sums of a certain column. However the value of the Sum depends
on a particular region being printed e.g. if the specific region is not
printed the value of the column should not be added to the sum. I use a
TppVariable, which is reset at group start and calculated (ie the column
value is added to the current value) at the AfterPrint event of the detail
band provided the specific region has been printed (ie visible) for this
record. Is this the correct way to do it? Does the AfterPrint fire only
once? I am asking because I used the OnCalc event of the TppVariable but
this is fired more than once in case of a page change.

Thanks

Yannis

Comments

  • edited May 2003
    Every event will fire more than once when stretching bands are involved. Use
    the variable's OnCalc and be sure to store the value in the Value parameter
    of the OnCalc event. This is the only way to get accurate calculations. RB
    performs some magic to track and restore the calculation values across page
    breaks for TppVariable values.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited May 2003
    That is what I thought. However it is not working that way when a page break
    is involved. The value of the last record of the previous page is added
    again.
    I am using RB 6.03 for Delphi 5.
    My bands are not stretching so in this case it works fine but I would like
    to do it the correct way in th OnCalc event.
    Any ideas?
    Yannis


  • edited May 2003
    Try placing the variable to calculate the total in the DetailBand. This way
    it will surely calculate correctly, as if it is in the footer band, it has
    to calculate, but the footer doesn't participate in the cahcing so it may
    calculate with one extra value when a page break occurs. This is why you
    should place the variable in the detail band. Then use this variable's value
    in the summary band calculations.


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.