A VBScript Version of VBA's IIf Function
The IIf (short for Immediate If) function is a simple but efficient function that's native to Visual Basic for Applications (VBA). You can, however, create a VBScript function that has the same functionality. Although VBScript versions of this function have been in use for a while, I thought I'd share my version for those of you who don't know about this helpful function.
The IIf function evaluates an expression and returns a specific value, depending on whether the expression evaluates to True or False. Thus, you can use the IIf function in place of VBScript's If...Then...Else statement.
As Listing 1 shows, the function contains only three lines of code, two of which are the Function and End Function statements. You place this function in your script, then call the function, using the syntax
IIf(expr, truepart, falsepart)
where expr is the expression you want to evaluate, truepart is the value or expression returned if expr is True, and falsepart is the value or expression returned if expr is False. For example, the calling code might look like . . .

