>Hi,
>I have DevideByZero exception in expression when LN_QTY=0D
>
>LN_RESULT = IIf(LN_QTY > 0D, LN_SUM / LN_QTY, -1D)
>
>I expect function return me -1D, but so far as I see, VB compiler evaluate every expression not depends from logical rule?
>
>Is it bug or feature? Is the same in C# ?
Naomi and Bill have pointed out that the LN_SUM/LN_QTY expression will be evaluated and you should use IF() but what are the types of the variables? If they are all doubles then you should not be getting an exception but a Nan result. For example:
Dim LN_QTY As Integer = 0D
Dim LN_SUM As Integer = 100D
Dim LN_RESULT As Double = LN_SUM / LN_QTY
Dim LN_RESULT2 As Integer = LN_SUM / LN_QTY
Also, FWIW, the C# equivalent works as expected regardless:
LN_RESULT = LN_QTY > 0d ? LN_SUM/LN_QTY : -1d;