This is a migrated thread and some comments may be shown as answers.

Textbox value "IIf" at runtime causing error

3 Answers 380 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Stuart
Top achievements
Rank 1
Stuart asked on 21 Dec 2015, 12:54 PM

In my report group section at the bottom of my report, totals are calculated.  Some calculations are dividing based on the Sum() of fields shown in the detail section.

 

If the textbox is defined with value at design time as follows: 

=IIF(Sum(Fields.NumberOfReceipts1) = 0,
   0,
   Sum(Fields.Sales1) / IIF(Sum(Fields.NumberOfReceipts1) = 0, 1, Sum(Fields.NumberOfReceipts1))
)

This works fine and there is no error.  However, because of the number of total boxes in the report - I ended up getting a Stack Overflow message just on entering the component.Initilializer() (First { bracket).  So decided to create these boxes at runtime:

textBox.Value = "=IIf(Sum(Fields.NumberOfReceipts1) = 0, 1, Sum(Fields.NumberOfReceipts1))";

But this now causes the following error:

"An error has occurred while processing TextBox 'rtNoSales12': An error has occurred while executing function IIf(). Check InnerException for further information. ------------- InnerException ------------- Exception has been thrown by the target of an invocation. ------------- InnerException ------------- Index (zero based) must be greater than or equal to zero and less than the size of the argument list."

How can I avoid the Divide by 0 error by defining report textbox values at runtime?

3 Answers, 1 is accepted

Sort by
0
Stef
Telerik team
answered on 24 Dec 2015, 11:56 AM
Hello Stuart,

When you use the IIf built-in function, both sides of the expression are evaluated. To avoid issues if one of the sides contains division, I can suggest you to use operators introduced as of Telerik Reporting Q1 2015 - Divide By Zero Error.

I hope this information is helpful.

Regards,
Stef
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Stuart
Top achievements
Rank 1
answered on 24 Dec 2015, 02:27 PM
The example I posted as 'runtime' doesn't do any division - and yet it fails....  I just wanted to show 1 instead of 0 if SUM(Fields.NumberOfReceipts1) = 0....  this was defined on a Telerik.Reporting.TextBox at runtime and causes the error I quoted.
0
Stef
Telerik team
answered on 24 Dec 2015, 02:45 PM
Hello Stuart,

Both expressions do not cause errors, in my tests. Test data is retrieved from AdventureWorks database, and the expressions are used as TextBox item's Value properties in a report's GroupFooterSection.
Tested with Telerik Reporting Q3 2015 SP2 v9.2.15.1216.

Please post the report definition, and several data records, which can be used for building a report for testing purposes.

Regards,
Stef
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
General Discussions
Asked by
Stuart
Top achievements
Rank 1
Answers by
Stef
Telerik team
Stuart
Top achievements
Rank 1
Share this question
or