Summing values in code
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
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
This discussion has been closed.
Comments
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
http://www.digital-metaphors.com
info@digital-metaphors.com
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
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
http://www.digital-metaphors.com
info@digital-metaphors.com