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

Calculations fail when the fields that are being calculated wraps over one or more pages

edited August 2003 in End User
I currently have a Main report with 1 subreport in it.
The main report gives a list of Type A Records.
For each Type A Record a list of Type B Records are displayed underneath the
specific Type A Record.
I want to count Field x in in Type B record only if that field contains a 1.

I've declared a global variable in the main report called CountB.
I clear/initiate CountB's value on the Title, BeforeGenerate event of my
subreport. (set it to 0).
On the Detail, BeforeGenerate event of the subreport i add 1 to CountB if
the value of Field x = 1;

In my main report I have a group.
In the group footer I have a variable that I set to CountB (summary or Field
x's all equal to 1).
This works perfectly as long as the list of Type B Records does not wrap
across 2 pages.
If the list of Type B Records does wrap accross 2 pages CountB is equal to 1
more than it should be.
I have established that this is because it is counted for each page it wraps
over. (Keeping the group together that it's not displayed on 2 pages does
not make a difference)

I managed to ge around that problem by checking the record id and making
sure that i don't count the previous one twice.
If the list of Typ B Records wrap over 3 pages ---> all hell brakes loose.

CountB's value is reset to 0 correctly so that's not the problem.

Is this a known issue and is there a different appoach that I can use?

Thank you very much
Jaline Richards.

Comments

  • edited August 2003
    You'll need to use a TppVariable. Store the calculations in the Value
    property of the variable and use its OnCalc event for the calculation.


    Cheers,

    Jim Bennett
    Digital Metaphors


  • edited August 2003
    I am using a TppVariable to store the value and I am using its OnCalc event
    for the calculations. This is however not the core of my problem.
    As I have explained the calculations works perfectly. I am trying to get the
    total of a field of a few records. On the BeforeGenerate event of the Detail
    band I do a calculation on the specific field and then add the outcome of
    the calculation to a variable containing the sum of these outcomes.
    Everything works perfectly except if the records that I'm going through to
    add the specific field's value wraps accross one or more pages. I've managed
    to get a workaround for this problem for now but as this is a very big
    problem I would like to know what else I can do to avoid this issue.
    The workaround is as follows:
    If you create a group that is the same group as whatever is in the Detail
    band and do your calculation on the BeforeGenerate event of this group you
    do not have the wrapping problem.

    I would like to have feedback regarding this problem and make sure that you
    understand what the core of the problem is. Please let me know if there's
    anything else you would like from me with regards to the example etc.

    Thank you very much for your help.
    Jaline Richards.



  • edited August 2003

    In your original post you stated that you are using a Global Variable and
    the OnBeforeGenerate event of the detail band to accumulate some
    calculations.

    Jim's response that you need to use TppVariable to perform all calculations
    is correct. You cannot use global variables to accumulate calculations -
    doing so produces incorrect results such as you describe.

    1. Check out the Calculations thread of the Tech Tips newsgroup for articles
    on performing calculations.

    2. Note that you can use two Variables: Variable1 and Variable2 and use
    Variable1.OnCalc to accumulate both values:

    Variable1.Value := Variable1.Value + {some calculation}
    Variable2.Value := Variable2.Value + {some calculation}



    --
    Nard Moseley
    Digital Metaphors
    http://www.digital-metaphors.com

    Best regards,

    Nard Moseley
    Digital Metaphors
    www.digital-metaphors.com
  • edited August 2003
    Thanks very much Nard,
    I understand now what was ment, and this solved my problem.
    Do you perhaps know of any documentation/books that are available on how to
    use reportbiulder end-user designer including wrap?

    Jaline Richards.


  • edited August 2003
    There is a Developer's Guide PDF in your RBuilder installation. In the PDF
    is a chapter called Code and there are also RAP tutorials in the PDF as
    well. The RAP tutorial Delphi projects are located in the RAP folder under
    the demos directory.


    Cheers,

    Jim Bennett
    Digital Metaphors


This discussion has been closed.