Taufiq Abdur Rahman
Taufiq Abdur Rahman

Reputation: 1388

RDLC Math error handing

I the expression below is not working giving #error result if txtTotalFixedAsset3 has 0

=IIf(ReportItems!txtTotalFixedAsset3.Value<> 0 ,(ReportItems!txtTotalFixedAsset.Value  /ReportItems!txtTotalFixedAsset3.Value)*100 , 0)

what am i going wrong?

=IIf(ReportItems!txtTotalFixedAsset3.Value<> cDec(0) ,(ReportItems!txtTotalFixedAsset.Value  /ReportItems!txtTotalFixedAsset3.Value)*100 ,cDec(0))

I also tried this. but no success. txtTotalFixedAsset3 value is of type decimal.

Upvotes: 1

Views: 395

Answers (1)

D Stanley
D Stanley

Reputation: 152501

It may be trying to evaluate the arguments in the Iif regardless of whether the condition is true or not. Try:

=ReportItems!txtTotalFixedAsset.Value /
     IIf(ReportItems!txtTotalFixedAsset3.Value = 0
        , 1
        , ReportItems!txtTotalFixedAsset3.Value)
     *100 

Of course this assumes that if txtTotalFixedAsset3 is 0 then txtTotalFixedAsset is 0 as well. If not then it truly is a divide by 0 error.

Upvotes: 2

Related Questions