count with a variable
Hi everybody,
I have got a report with several groups inside.
This report, to sum up, lists many enterprises.
I am using a variable to count the number of enterprises in a group.
For example, in a group, I have got 6 lines for 2 enterprises. The variable
must give 2.
The problem is :
When the group is only on one page, the result is good, but when this is on
several pages, the result is false and I do not understand this one.
If I am going on the next page and return on the previous, the result is not
the same.
Someone has got an idea ?
Thanks a lot
Laurent
I have got a report with several groups inside.
This report, to sum up, lists many enterprises.
I am using a variable to count the number of enterprises in a group.
For example, in a group, I have got 6 lines for 2 enterprises. The variable
must give 2.
The problem is :
When the group is only on one page, the result is good, but when this is on
several pages, the result is false and I do not understand this one.
If I am going on the next page and return on the previous, the result is not
the same.
Someone has got an idea ?
Thanks a lot
Laurent
This discussion has been closed.
Comments
in which event are you performing your calculation ? I had this problem when
I was doing calculations in the BeforePrint event. DON'T DO THIS !!! Use
instead OnCalc or OnPrint for your counting. If it's just to know how many
enterprises have been printed on your report, OnPrint can fit.
David Caouette (du Qu?bec)
Omniciel International
"Laurent Monchy" a ?crit dans le message de
David is correct. You are going to want to use the OnCalc event of a
TppVariable when making calculations in a report. Also try setting the
Report.CachePages to True and see if that helps when navigating backward
through your report.
----------------------------------------------------------------------
TECH TIP: Performing Calculations
----------------------------------------------------------------------
Calculations can be done either on the data access side
or within ReportBuilder.
When designing reports there are always decisions to be made as to
how much processing to do on the data side versus the report side.
Usually doing more on one side can greatly simplify the other. So it is
often a personal choice based on the power and flexibility of the data
and report tools being used.
DataAccess
----------
a. Use SQL - using SQL you can perform many common calculations:
example: Select FirstName + ' ' + LastName As FullName,
Quantity * Price AS Cost,
b. Delphi TDataSets enable you to create a calculated TField object
and use the DataSet.OnCalcFields event
c. Perform any amount of data processing, summarizing, massaging
etc. to build a result set (query or temp table) to feed to the report.
ReportBuilder
-------------
Calculations in ReportBuilder are performed primarily using
the TppVariable component.
a. Set the Variable.DataType
b. Code the calculations using the Variable.OnCalc event.
c. Use the Timing dialog to control the timing of the OnCalc event.
To access the Timing dialog, right click over the Variable
component and select the Timing... option from the speed menu.
d. Set the LookAhead property to True, when you need to display
summary calculations in the title, header, group header, etc.
e. To perform calculations based on the results of other
calculations use the Calc Order dialog of the band. To access
the Calc Order dialog, right click over the Band component
and select the Calc Order... option from the speed menu.
By using TppVariable components ReportBuilder will take care of caching
intermediate results of accumlated calcs that cross pages.
There are a number of calculation examples in the main demos.dpr
project.
---
Additional Notes:
1. Do NOT use Band.BeforePrint or Band.AfterPrint. These events fire
multiple times and therefore should not be used for calculations.
2. Do NOT store results in variables that exist outside of the reports.
For example - form level variables.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
The calculation is in the event BeforeGroupBreak.
I go to try your idea.
Thx
Laurent
I tried the David idea too, but it does not work.
Laurent
only fires IF the band actually prints. As others have mentioned do not use
the BeforePrint event of the band as it can potentially fire multiple times
and can potential fire even if the band does not actually print. The only
issue we have with doing it this way is that if the Group is split across
multiple pages then the event fires a second time. We solved this problem by
ensuring the Keep Together property of the band was set to True.
Scott
When a group extends beyond one page, how far off is the group count? Have
you tried using a DBCalc component yet set to Count(*) and ResetGroup set to
the current group? This may be an easier option for what you want to
accomplish.
--
Regards,
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com
Nico Cizik
Digital Metaphors
http://www.digital-metaphors.com