Using the In-line If (IIF) Function

The traditional way to add conditional execution to one or more functions is with If and Else statements. A relatively simple alternative is the In-line If function (abbreviated IIF). The IIF function provides much of the functionality available with If and Else statements, but it doesn't require the use of multiple lines of Visual Basic. In fact, it is the only way to add conditional execution to a single-line expression. It is also easy enough to work with that many users will use it when possible in multi-line scripts, even though they could have used separate If and Else statements.

The IIF function syntax is as follows:

IIF(<ConditionalExpression>,<ExpressionIfTrue>,<ExpressionIfFalse>)

Although the IIF function is available in a number of computer languages, it is not native to Visual Basic. The manufacturers of BarTender created the version provided in the Script Assistant for your use.

The IIF function contains three expressions:

Evaluating the Conditional Expression of the IIF Function

The IIF function first examines the conditional expression (the first term in the function) to see if it is True or False. Examples of a conditional expression include:

Completing Execution of the IIF Function

The "ExpressionIfTrue" term in the IIF function is executed if the conditional expression is True. The "ExpressionIfFalse" term is executed if the conditional expression is False. Only one of these two expressions will get executed each time the IIF function is executed. The "ExpressionIfTrue" and "ExpressionIfFalse" expressions can be any valid single line expression, including additional ("nested") IIF functions.