Kdev
April 25th, 2001, 10:37 AM
I want to know why VB insists on executing both the true and false part of a iif statment when it should only do one part.
Example:
If nTotOutput = 0 then
fLinearity = 0
else
fLinearity = (1 - (nTotDev / nTotOutput))
End If
fLinearity = IIf(nTotOutput = 0, 0, (1 - nTotDev / nTotOutput)))
Both of these bits of code should do the same thing however the iif statement will produce an error when nTotOutput = 0 because of the division by 0 problem. Why must VB check that part of the statement when it is going to return the other part anyway?
-K
Example:
If nTotOutput = 0 then
fLinearity = 0
else
fLinearity = (1 - (nTotDev / nTotOutput))
End If
fLinearity = IIf(nTotOutput = 0, 0, (1 - nTotDev / nTotOutput)))
Both of these bits of code should do the same thing however the iif statement will produce an error when nTotOutput = 0 because of the division by 0 problem. Why must VB check that part of the statement when it is going to return the other part anyway?
-K