Globa Variable
I have a global variable that I use to keep running total of a transaction
amounts in the subreport. Then in the main report on BeforePrint of the
Summary band I assign the global variable value to the diplayed variable in
the report.
This all works fine and calculations are fine with one exception. In
preview, if I go to the end of the document where the Summary band is
displayed, it is correct. However, if I go back to beginning of document
and then return to the end, the value has increased and will do so each time
I do this.
Strangely, it does not double and I have not been able to determine where it
is getting the increase. If I go back just one or two pages and then go to
the end, nothing the total does not change. It only changes if I go to
beginning of docuement and then to end.
Any thoughts?
amounts in the subreport. Then in the main report on BeforePrint of the
Summary band I assign the global variable value to the diplayed variable in
the report.
This all works fine and calculations are fine with one exception. In
preview, if I go to the end of the document where the Summary band is
displayed, it is correct. However, if I go back to beginning of document
and then return to the end, the value has increased and will do so each time
I do this.
Strangely, it does not double and I have not been able to determine where it
is getting the increase. If I go back just one or two pages and then go to
the end, nothing the total does not change. It only changes if I go to
beginning of docuement and then to end.
Any thoughts?
This discussion has been closed.
Comments
1. When making calculations inside a report, only using the OnCalc event of
a TppVariable. Which event are you updating the value of the global
variable?
2. As a test, try setting the Report.CachePages to True.
----------------------------------------------------------------------
TECH TIP: Performing Calculations
----------------------------------------------------------------------
Calculations can be done either on the data access sideor 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
Before Generate event.
Then in the main report in summary band, I have a TppVariable and I am
assigning the global variable value to the TppVariable in the OnCalc event
of the TppVariable.