For most of C-like programming languages, conditional (ternary) operator is more concise than If statement. And it is also available in VBA and VB .NET.
It is convenient but need to notice that IIF will always evaluate all arguments. See below example:
The syntax is similar, but the result will be only evaluated with the Boolean expression.
References:
IIf Function
If Operator (Visual Basic) | Microsoft Docs
VBA Conditional Operator
The function "IIF" exists since VB6, syntax seems like below:It is convenient but need to notice that IIF will always evaluate all arguments. See below example:
VB .NET Conditional Operator
To improve IIF problem, there is IF operator in VB .NET.The syntax is similar, but the result will be only evaluated with the Boolean expression.
References:
IIf Function
If Operator (Visual Basic) | Microsoft Docs
Comments
Post a Comment