IIF Syntax
I am attempting to prevent a divide by 0 error in the group footer of my report using
[IIF([grpTotSales]=0,0,[grpTotShrinkValue]/[grpTotSales])]
where grpTotSalse and GrpTotShrinkValue are Totals used in the Report
if grpTotSales is 0, the report generates an error and will not run
An unhandled exception of type 'System.Exception' occurred in FastReport.dll
Additional information: Text182: Error in expression: IIF([grpTotSales]=0,0,[grpTotShrinkValue]/[grpTotSales])
Can anyone provide the proper syntax.
[IIF([grpTotSales]=0,0,[grpTotShrinkValue]/[grpTotSales])]
where grpTotSalse and GrpTotShrinkValue are Totals used in the Report
if grpTotSales is 0, the report generates an error and will not run
An unhandled exception of type 'System.Exception' occurred in FastReport.dll
Additional information: Text182: Error in expression: IIF([grpTotSales]=0,0,[grpTotShrinkValue]/[grpTotSales])
Can anyone provide the proper syntax.
This discussion has been closed.
Comments
Hi,
which .NET language is set in your report? C# or VB?
For C# the expression should look like this [IIf([grpTotSales] == 0, 0, [grpTotShrinkValue]/[grpTotSales])]
For VB it should be like yours: [IIf([grpTotSales] = 0, 0, [grpTotShrinkValue]/[grpTotSales])]
I did change the statement to IIF([grpTotSales]=0,0,1) , which ran correctly, so the error is in the [grpTotShrinkValue]/[grpTotSales] expression
Bill
Hello!
If you're using C# (recommended): replace IIF with the actual short-circuit ternary operator ?: (and use == instead of =):
[([grpTotSales] == 0 ? 0 : [grpTotShrinkValue] / [grpTotSales])]If you’re using VB.NET, and since IIf in VB isn’t lazy either, rewrite the denominator so you don’t divide by zero
([IIf([grpTotSales] = 0, 0, [grpTotShrinkValue] / IIf([grpTotSales] = 0, 1, [grpTotSales]))]), or check for If grpTotSales = 0 Then in the Text182_BeforePrint event