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

Manual Calculations Problem with Print Preveiw

edited November 2004 in General
I have no choice to do some manual calculations.

problem is that on the preview the data is correct
but when you click to print it, the data is wrong.

If i change the report device to printer so that I don't
get the preview the report prints fine.

How do i fix the problem.

I have tried putting the calculations in several places
such before print and before generate.

I have subtotals and final total.
in most cases the final total get doubled.

TIA

Comments

  • edited November 2004
    Hi Mojoala,

    If you are making calculations inside a report, you need to be sure you are
    using a TppVariable component and performing the calculations inside the
    OnCalc event. See the article below for more information.

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

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited November 2004
    thanks I will try that too.

    I may not get back to this problem until sometime
    next week or later.

    If I run into problems, what should I do?
    Respond to this question or post a new question?

    thanks Nico
  • edited November 2004
    Hi Mojaola,

    If the question sill pertains to this topic, it would be useful to keep this
    thread going. This however is completely up to you, feel free to start a
    new thread if you like.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited November 2004
    ok thanks nico
  • edited November 2004
    I have to work on this now nico.

    Okay here is what one group of the report looks like:

    OrderNo N.C. Code Price
    _________________________________________
    242342 406 24.96
    242371 406 56.68
    242371 406 3.68
    242376 406 76.96
    242376 406 3.64
    _______________________________________
    # of N.C.s 3 Total 165.88

    the program breaks on the N.C. code

    the # of N.C.s is the result of a comparison of
    current orderno and the holdorderno so what i am
    counting up is the distinct orderno's but i have to show

    my code is on the before print for the detail band as follows:

    procedure TReportPONC.DetailBandPONCBeforePrint(Sender: TObject);
    begin
    with plPONC.DataSource.DataSet do
    begin
    if FieldByName('OrderNo').AsInteger <> OrderNoHold then
    begin
    PONCEvent := PONCEvent + 1;
    end;
    end;
    end;

    and here is code for the before group foot print:

    procedure TReportPONC.grpFootBandBeforePrint(Sender: TObject);
    begin
    lblPONCEvent.Caption := IntToStr(PONCEvent);
    end;

    and here is code for the after group foot print:

    procedure TReportPONC.grpFootBandAfterPrint(Sender: TObject);
    begin
    AllPONCEvents := AllPONCEvents + PoncEvent;
    PONCEvent := 0;
    end;

    and here is the before summary print:

    procedure TReportPONC.ppSummaryBand1BeforeGenerate

    (Sender: TObject);
    begin
    lblTotalPONCEvents.Caption := IntToStr(AllPONCEvents);
    end;

    now how would i fix this using TppVariable

    I first tried this after putting the ppVariable1 in the group footer.

    procedure TReportPONC.ppVariable1Calc
    (Sender: TObject; var Value: Variant);
    begin
    with plPONC.DataSource.DataSet do
    begin
    if FieldByName('OrderNo').AsInteger <> OrderNoHold then
    value := value + 1;
    end;
    end;


    it gives different values on the first group on the second page
    with traversal it is giving a 0 instead of a 1.
    but when i change timing to
    DataPipelineTraversal it gives a 2 instead of a 1

    i then put it in the the summary band
    it still gave a different value than i calculated

    my summary says 20 but the varible says 19 so it still doing
    what i described earlier.
    and that was with transversal but when i change timing to
    DataPipelineTraversal it 21
    neither one will give 20

    Help!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  • edited November 2004
    i just unchecked "keep group together"

    all the numbers come out right now.

    but i want to keep the group together

    so how do we fix this problem?

    thanks
  • edited November 2004
    Hi Mojoala,

    I would suggest placing a TppVariable inside your detail band with its
    visibility property set to False and in its OnCalc event, make your
    calculation, updating the value of another visible TppVariable located
    inside your group footer.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited November 2004
    Hi Nico

    I did that and the results came out bad on the first group
    of the second page.

    so I made the variable visible in the detail line so I could
    see the results.

    on a regular transversal the detail variable is getting a 0
    and on the pipeline transversial it is getting a 2
    but on the print preview it is showing correctly on both
    instances.

    also the summary varible is affected too. It just seems to
    not like the "keep groups together".

    any other ideas?


    thanks, mojoala
  • edited November 2004
    Hi Mojoala,

    Please construct a simple example demonstrating this behavior that I can run
    on my machine and send it in .zip format to support@digital-metaphors.com
    and I'll take a look at it for you.

    --
    Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com

    Best Regards,

    Nico Cizik
    Digital Metaphors
    http://www.digital-metaphors.com
  • edited November 2004
    I emailed just now.
This discussion has been closed.