IIF in text component with divisions -> errors

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

IIF in text component with divisions -> errors

Post by Jennypi »

Hi all,

I'm facing a crazy problem, can't manage to fix it by myself, although it looks quite simple.
In the text editor of a text component, I typed this code:

Code: Select all

{IIF(Sowing.number_of_seeds==0,
	"?",
	IIF(Sowing.fruit_number==0,
		IIF (Sowing.number_of_young_plants==0,
			"?",
			Sowing.number_of_seeds/Sowing.number_of_young_plants),
		Sowing.number_of_seeds/Sowing.fruit_number))}

When I display the report with the data, this code doesn't work properly. I got errors "Attempted to divide by zero", although I take into account those divisions by zero in the code, with the conditions.
Thing that is strange is that if I replace the 2 divisions included in the code by simple text (like "blahblah"), everything is working fine, data are going to the good "if" according to what values are null.
I tried everything, changed "==0" with "==null", changed the condition sequence, etc... I'm going nuts! As soon as I add a division, report fails!

On this link you will find the report and data sample (data as they are when doing "View data" with the "real" report, from the DB. Maybe you'll need to change "null" data to "0", I don't know exactly how the csv should look like in that case).

Could you please help me?
Hope this is understandable. I can join screenshots if it helps.

Thanks!
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

IIF in text component with divisions -> errors

Post by HighAley »

Hello.

The division by zero error occurs because IIF() is a function. And when you call function all arguments is calculated.
Please, try to use next code instead yours:

Code: Select all

{Sowing.number_of_seeds==0?
	"?":
	(Sowing.fruit_number==0?
		(Sowing.number_of_young_plants==0?
			"?":
			(Sowing.number_of_seeds/Sowing.number_of_young_plants).ToString()):
		(Sowing.number_of_seeds/Sowing.fruit_number).ToString())}
Thank you.
Jennypi
Posts: 361
Joined: Mon Nov 17, 2008 7:13 am
Location: France

IIF in text component with divisions -> errors

Post by Jennypi »

Thanks a lot, it's working perfectly.
Could you please explain this code to me? "?" use is another way to have conditions?

thx
HighAley
Posts: 8430
Joined: Wed Jun 08, 2011 7:40 am
Location: Stimulsoft Office

IIF in text component with divisions -> errors

Post by HighAley »

Hello.
Jennypi wrote:Thanks a lot, it's working perfectly.
Could you please explain this code to me? "?" use is another way to have conditions?
We are always glad to help you.
It's the C# conditional operator. Please, read this article http://msdn.microsoft.com/en-us/library/ty67wk28.aspx

Thank you.
Post Reply