VBA/Excel/Access/Word/Language Basics/IIF — различия между версиями

Материал из VB Эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 16:33, 26 мая 2010

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