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

Proper way to add dbcalcs

edited July 2004 in End User
I have a variable thats value is the sum of three dbcalc's in its
calculations screen it says

value := DBCalc1.Value + DBCalc2.Value + DBCalc3.Value;

but this results in an empty value. What is the proper way?

Comments

  • edited July 2004
    Hi Chris,

    Where is this TppVariable located in your report. As a test place a break
    point on the line below and check the values of each DBCalc. If the value
    is 0, then the DBCalcs have not yet been calculated and you need to change
    the print order of the variable.

    DBCalcs are good for simple one time calculations across single bands. When
    you need to make more complex calculations such as a sum of sums, it is
    better to use TppVariables.

    --
    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited July 2004
    Nico Cizik (Digital Metaphors) wrote:

    The DBCalc1, DBCalc2, DBCalc3, the Variable1 are all in a subreport
    summary band. I placed them on in that order. The DBCalc1 is a sum of
    one field of the data, dbcalc2 is the sum of another field of the data
    and dbcalc3 is the sum of a third field in the data. Variable1 is the
    sum of the three dbcalc's.
  • edited July 2004

    You might be able to control the ordering of the calculations by using
    BringToFront/SendToBack to control the z-order. (BTW, the report tree tool
    windows displays the components in z-order so you can see the effects of
    BringToFront/SendToBack visually).

    Otherwise you will need to replace the TppVariable components with DBCalcs.
    Then you can specify the CalcOrder for the TppVariables. Press the right
    button while positioned over the white space of the band and select
    CalcOrder...


    ------------------------------------------------------------------------
    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.



    --
    Tech Support mailto:support@digital-metaphors.com
    Digital Metaphors http://www.digital-metaphors.com




    --


    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
This discussion has been closed.