Incorrect use of IIf, was: Dividing by 0 yielding warning and unexpected results even though this situation should never happen

Following code is giving me warnings:

IIF(x>0, z = Volume/x > y, z = False);

It's complaining Volume/x is dividing by 0 however the if condition prevents this condition from ever getting triggered. I think as a result of this i'm getting weird behavior and my scan isn't yielding any results...

Thanks!

Your code is incorrect.

The Users' Manual offers plenty of information about IIF. Please read the docs on IIF and IIF common mistake doc. IIF() is NOT control flow statement but an array FUNCTION. Function evaluates all arguments. The docs clearly say what is wrote is WRONG.

This thread is a must-read for you (actually it is PINNED thread for everyone):

You should have written:

z = IIf(x>0, Volume/x > y, False); // note the ASSIGNMENT of RESULT of the function

All functions evaluate their arguments prior to call and arguments are passed by value like in classic C language:

2 Likes