Visual Basic includes the Immediate If function (IIf), but VBScript (VBS) does not. However, you can copy this code to VBS to allow the IIf function to be used:
'VB Function not included in VBS
Function IIf(Expression, TruePart, FalsePart)
If Expression = True Then
If IsObject(TruePart) Then
Set IIf = TruePart
Else
IIf = TruePart
End If
Else
If IsObject(FalsePart) Then
Set IIf = FalsePart
Else
IIf = FalsePart
End If
End If
End Function
The function can return both objects and basic data types. Heres a sample function from an ASP page that calls the IIf function:
' Return a True or False value for a checkbox
Function CheckBoxValue(Name)
CheckBoxValue = _
IIf(Request.Form(Name) = "on", True, False)
End Function