using variable to calculate TOTAL

Stimulsoft Reports.NET discussion
Post Reply
mihiri2
Posts: 43
Joined: Mon Apr 08, 2013 2:29 am

using variable to calculate TOTAL

Post 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
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: using variable to calculate TOTAL

Post 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.
mihiri2
Posts: 43
Joined: Mon Apr 08, 2013 2:29 am

Re: using variable to calculate TOTAL

Post 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
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: using variable to calculate TOTAL

Post 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.
Attachments
ReportSample.mrt
(21.76 KiB) Downloaded 282 times
mihiri2
Posts: 43
Joined: Mon Apr 08, 2013 2:29 am

Re: using variable to calculate TOTAL

Post by mihiri2 »

thanks Aleksey, i will try this.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Re: using variable to calculate TOTAL

Post by Alex K. »

Hello

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

Thank you.
Post Reply