VBA/Excel/Access/Word/Language Basics/IIF
Содержание
Choosing an Action Using IIf(expr, truepart, falsepart)
Sub iffDemo()
Debug.Print IIf(1 < 10, "True. 1 is less than 10", "False. 1 is not less than 10")
End Sub
The Immediate If (IIf)
Function EvalSales(curSales As Currency) As String
EvalSales = IIf(curSales >= 100000, "Great Job", "Keep Plugging")
End Function
Use IIF(conditional test, value for True, value for False)
Sub IIFSub()
Dim strMessage As String
Dim intNum As Integer
intNum = 12
strMessage = IIf(intNum > 10, "Number is greater than 10", "Number is less than 10")
Debug.Print strMessage
End Sub
Use IIF to calculate value
Function Tax(ProfitBeforeTax As Double) As Double
Tax = IIf(ProfitBeforeTax > 0, 0.3 * ProfitBeforeTax, 0)
End Function
Sub test()
MsgBox Tax(100)
End Sub