IIF |
IIF(expr, truepart, falsepart) |
Returns one of two parts, depending on the evaluation of an expression. |
expr | The expression you want to evaluate. |
truepart | The value or expression returned if "expr" is True. |
falsepart | The value or expression returned if "expr" is False. |
REMARKS |
* This function always evaluates both truepart and falsepart, even though it returns only one of them. Because of this, you should watch for undesirable side effects. * For example, if evaluating falsepart results in a division by zero error, an error occurs even if expr is True. * This is also better known as the Immediate If function. * This function should not be used as it leads to code being harder to read and understand. * An alternative to using this function is to use the If - Then - Else statement. * You can use the CHOOSE function to returns the value from a list of values based on an index number. * You can use the SWITCH function to return a value based on expressions. * The equivalent .NET function is Microsoft.VisualBasic.Interaction.IIF * For the Microsoft documentation refer to learn.microsoft.com |
IIF(true, "It is true", "it is false") = "it is true"
IIF(false, "It is true", "it is false") = "it is false"
If (iValue > 10) Then
Call MsgBox("number is greater than 10")
Else
Call MsgBox("number is less than or equal to 10")
End If
© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited Top