Implementing elegant if else
A typical if else condition in VBScript would look like below
View Code QTP
If (message = "ok") Then Msgbox "I am calling ok" Else Msgbox "I am calling not ok" End if |
VB provides a elegant function named IIf for such small if else conditions. The function can be easily witten in VBScript
View Code QTP
Public Function IIf(ByVal pCondition, ByVal trueValue, ByVal falseValue) If pCondition Then IIf = trueValue Else IIf = falseValue End If End Function |
Now the same code be written in single line of code
View Code QTP
Msgbox "I am calling " & IIf(message="ok","ok", "not ok") |