Page 1 of 1

IIF in text component with divisions -> errors

Posted: Mon Dec 05, 2011 1:40 pm
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!

IIF in text component with divisions -> errors

Posted: Tue Dec 06, 2011 3:05 am
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.

IIF in text component with divisions -> errors

Posted: Tue Dec 06, 2011 5:24 am
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

IIF in text component with divisions -> errors

Posted: Wed Dec 07, 2011 5:44 am
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.