Page 1 of 1

Problem with calculation in AfterPrint event

Posted: Mon Nov 15, 2010 9:27 am
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!

Problem with calculation in AfterPrint event

Posted: Tue Nov 16, 2010 1:39 am
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.

Problem with calculation in AfterPrint event

Posted: Tue Nov 16, 2010 7:14 am
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.

Problem with calculation in AfterPrint event

Posted: Tue Nov 16, 2010 8:39 am
by Alex K.
Hello,

Please see the sample report in attachment.

Thank you.



Problem with calculation in AfterPrint event

Posted: Tue Nov 16, 2010 8:54 am
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.

Problem with calculation in AfterPrint event

Posted: Tue Nov 16, 2010 9:05 am
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.

Problem with calculation in AfterPrint event

Posted: Tue Nov 16, 2010 12:01 pm
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.

Problem with calculation in AfterPrint event

Posted: Tue Nov 16, 2010 12:39 pm
by Alex K.
Hello,

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

Thank you.