Problem with calculation in AfterPrint event

Stimulsoft Reports.NET discussion
Post Reply
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Problem with calculation in AfterPrint event

Post by Jennypi »

Hi,

In my report, I would like a calculation to be done.
Example:

Code: Select all

Code | Numbers | First number
A    |10       |1
B    |4        |11
C    |3        |15
D    |7        |18
As you can see, "First number" of B = FirstNumber(A)+ numbers(A), and so on.

So I defined a variable. In the BeforePrint event of the report, I initialize my variable to 1:

Code: Select all

Variable = 1;
and in the AfterPrint event of the databand I defined:

Code: Select all

Variable = Variable +int.Parse(source.number.ToString());
It is working very well, except that the variable goes back to 1 on each page.
How can I avoid that? Where else could I initialize my variable?

Hope this is understandable.

Thanks!
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Problem with calculation in AfterPrint event

Post by Alex K. »

Hello,

In this case, you can use the following code in Before Print event on DataBand component:

Code: Select all

DataSource.Prior();
Variable1 += DataSource.Number;
DataSource.Next();
Please see the sample report in attachment.

Thank you.
Attachments
696.SampleReport.mrt
(20.21 KiB) Downloaded 315 times
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Problem with calculation in AfterPrint event

Post by Jennypi »

Thanks for your reply.

I have set my variable's default to

Code: Select all

int.Parse(TextBoxControl1.Text)
(because it will be typed by users)
and I have put

Code: Select all

labels.Prior();
Variable += labels.nb_y_plants;
labels.Next();
In the BeforePrint event of the databand.

I am getting this error:
Method : [createInstance]
Exception has been thrown by the target of an invocation
Could you please help me in fixing this?

Thank you.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Problem with calculation in AfterPrint event

Post by Alex K. »

Hello,

Please see the sample report in attachment.

Thank you.


Attachments
697.SampleReport.mrt
(21.85 KiB) Downloaded 324 times
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Problem with calculation in AfterPrint event

Post by Jennypi »

Thanks for your example. I have modified my report accordingly, but I am still getting the error.
It seems that it is because of the default value of the variable which I defined like this:

Code: Select all

int.Parse(TextBoxControl1.Text)
When I replace this with "1", it is working.

Maybe my syntax is wrong?

Thank you.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Problem with calculation in AfterPrint event

Post by Alex K. »

Hello,

On the moment of the creation and defining of the default value for the your variable, the TextBoxControl1 component has not yet been implemented and, therefore, you get an error. Please use a specific value to specify the default value for a variable.

Thank you.
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

Problem with calculation in AfterPrint event

Post by Jennypi »

Ok, I set 1 as a default value for my variable and in the BeforePrint event of the databand I put:

Code: Select all

if (labels.Position != 0)
{labels.Prior();
Variable += labels.nb_y_plants;
labels.Next();}
if (labels.Position == 0)
{Variable=int.Parse(TextBoxControl1.Text);}
It seems to work fine.
Does it seem correct to you?

Many thanks for your help.
Alex K.
Posts: 6488
Joined: Thu Jul 29, 2010 2:37 am

Problem with calculation in AfterPrint event

Post by Alex K. »

Hello,

Yes, it's correct.
Let us know if you need any additional help.

Thank you.
Post Reply