Page 1 of 1

using variable to calculate TOTAL

Posted: Thu May 12, 2016 12:56 am
by mihiri2
I have a report with the following structure:

Header
Group Header
Data Band
Group Footer
Footer

Now Data band has an amount being displayed and I use a variable to calculate total for each group, So on Data Band Rendering:-
vTotal += dsBQItem.REVISEDAMT;

My Requirement is I display this on Group Header, Not on Group footer.

I do not want to use SUM function..

However the variable vTotal is not calculated yet when group header is printed. so always it gets printed as 0.
It gets calculated only when data band is actually printed, but by this time group header was already printed with a 0 vTotal variable.

How can I achieve this requirement? Is it possible to do that?


Thanks

Re: using variable to calculate TOTAL

Posted: Fri May 13, 2016 7:47 am
by Alex K.
Hello,

In this vase, you can use the Double Pass. In the first pass calculate all necessary values and in the second pass show it.

Thank you.

Re: using variable to calculate TOTAL

Posted: Mon May 16, 2016 12:06 am
by mihiri2
How does Double Pass work?

So when I do double pass, first time all the calculations are done, in second pass, aren't they set back to 0?

How does it know the total for each group on the second pass?

Thanks

Re: using variable to calculate TOTAL

Posted: Mon May 16, 2016 7:15 am
by Alex K.
Hello,

You can use an array or a hashtable for storage the calculated value.
For example

Code: Select all

if (IsFirstPass)
{
  vTotal += dsBQItem.REVISEDAMT;
  hashTable[GroupHeaderValue] = vTotal;
}
Please check the sample report in the attachment. You could find additional code in BeforePrint events of the GrouipHeadr and DataBand.

Thank you.

Re: using variable to calculate TOTAL

Posted: Mon May 16, 2016 11:16 pm
by mihiri2
thanks Aleksey, i will try this.

Re: using variable to calculate TOTAL

Posted: Tue May 17, 2016 6:05 am
by Alex K.
Hello

Ok.
Let us know if you need any additional help.

Thank you.