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

Where to sum up values... Preview <> Printout

edited January 2004 in General
Hi,

I used the BeforePrint event of my detail band for summing up a field -
and had to find out, that it seems like if a band is printed on the top
of the next page RB calls before print when trying to print it on the
bottom of the previous page. Due to this this band is counted double
times: 1st when RB tests whether it fits at the end of the page and
second when it's printed on the next page.

I changed my code in order to sum up my values within "AfterPrint" -
this seemed to work - but now I get a different Sum within the preview
and the "real" printout.

So, if I have the follwing:

categorie Valid Value
A True 5
A False 3
B True 1
A True 1

I want to have something like that to sum up my values:

IF Valid then
Sum[A]=Sum[A]+Value

... where should I put that code into in order to have the proper value
displayed? And why do I get different results within the preview
(wrong) and the printout (correct)?

Kind regards,

Mark Meyer

Comments

  • edited January 2004
    Hi,

    I just placed a "variable" component within the summary band and
    assigned my "sum-up-routine" to its OnCalc-Event.

    I still get different results for previewing and printing - but I
    managed to find out, where the problem is:

    My test-report has two pages. After generating the first page, the
    preview-form is displayed.

    If I press "next page" a correct sum is displayed within the preview at
    the end of page 2.

    If I press "last page" the value displayed is too high...

    In both cases the result is OK when printing the report.

    So.... ???

    May I say that it took me about a week just to create this report? And
    keeping groups together still is ignored - Nico, did you manage to find
    out something using my example-files?

    Mark
  • edited January 2004
    Hi Mark,

    This is the correct way you will want to make calculations in ReportBuilder.
    Please see the following example and read the article below on how to use
    TppVariables with the OnCalc event correctly. Sorry about the delay in
    response from your other issue, I will answer you through e-mail.

    http://www.digital-metaphors.com/tips/VariablesForGroupTotalOfCalculatedField.zip

    ------------------------------------------------------
    Tech Tip: Calculating a Summary based on Group Totals
    ------------------------------------------------------

    Question: I am using a Variable in the Group Footer to conditionally
    calculate totals for each group. I want to add a second Variable to the
    Summary that accumulates the results calculated for each group.

    The following example uses two Variable components: vCustomerTotal and
    vCustomerSummary. The variable vCustomerTotal has its Timing defined to
    Reset on GroupEnd.


    There are two options for accumulating the summary total.

    1. Use the vCustomerTotal OnCalc event to accumulate the detail and the
    summary.

    example:

    procedure vCustomerTotalOnCalc(Sender: TObject; var Value: Variant);
    begin

    if (plCustomer['Amountpaid'] > 100.00) then
    begin
    {sum detail}
    Value := Value + plCustomer['Amountpaid'];

    {accumulate summary}
    vCustomerSummary.Value := vCustomerSummary.Value +
    plCustomer['Amountpaid'];
    end;

    end;


    2. Set the timing of the Summary OnCalc to "GroupBeforeFooter" and
    accumulate the detail variable results. Note that here we use
    GroupBeforeFooter because the detail variable has its Reset defined as
    "GroupEnd" - implying that if we try to use GroupEnd for our summary
    calculation the accumulated results will be 0.

    example:

    procedure vCustomerTotalOnCalc(Sender: TObject; var Value: Variant);
    begin

    {sum detail}
    if plCustomer['Amountpaid'] > 100.00 then
    Value := Value + plCustomer['Amountpaid'];

    end;


    procedure vCustomerSummaryOnCalc(Sender: TObject; var Value: Variant);
    begin

    {accumulate summary}
    Value := Value + vCustomerTotal.Value;

    end;

    --
    Best Regards,

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

    I downloaded your demo

    http://www.digital-metaphors.com/tips/VariablesForGroupTotalOfCalculated
    Field.zip

    First I started it "as is, clicked on "Print", maximized the Preview
    Window and clicked on "Last Page" - a sum of 193,995,857.15 $ is shown
    on the last page (Page No. 56).

    Then I edited the sub report and changed the height of the detail band
    to "0.5".

    After compiling and restarting the demo, i clicked on "Print" again,
    maximized the window and clicked "Last Page" - and: The sum displayed
    as Grand Total now reads 223,351,315.30 $ (now on page 93).

    If I take a closer look at the first group, I see that in the first
    case the whole

    I placed to PDF-Files to show this issue on

    http://www.webserv1.de/temp/normaldemo.pdf

    and

    http://www.webserv1.de/temp/detailband05.pdf


    Though in my case the printout always is correct, within the demo even
    the printout has an incorrect sum on it.

    Well - let me say that I'm glad to be able to show this within the
    demo, I thought I was getting mad within the last days ;-)

    Kind regards,

    Mark
  • edited January 2004
    Sorry Nico, if I ask again - but I have an app here ready to ship and
    the only thing that keept me from doing so a week ago is that I
    implemented RB7 into my app.

    So - I do not have to get an update or workaround today - but the
    information if my two problems (wrong sum-values and KeepTogether does
    not work with more than one group) can be recreated with the demo I
    sent would help.

    If it takes long to build a fix for that problem, I'd have to put the
    QuickReport-Reports back into my app (though there are a few features
    within the new reports that I'd have to do double times in this case).

    Kind regards,

    Mark
  • edited January 2004
    Mark,

    As it turns out, the nested group issue may be causing both problems (as the
    behavior only begins to happen when that first nested group is added). I am
    currently working on debugging the KeepTogether issue and hopefully once
    this is fixed, the other problems will solve themselves. Thanks for your
    patience, I'll keep you updated.

    --
    Best Regards,

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

    that's OK for me - just wanted to know wether I have to pay attention
    to this issue at the moment. I'll publish a beta-release for those
    customers waiting urgently for the new features and will wait for the
    final release until this issue is fixed.

    Kind regards,

    Mark
This discussion has been closed.