IF ... Then ... Else and IF ... Then ... ElseIf
The If ... Then ... Else statement is used to define two blocks of conditions - true and false.
Example:
Note that End If statement is needed in this case as well since there is more than one block of statements
The IF ... Then ... ElseIf is used to test additional conditions without using new If ... Then statements.
For Example:
Note that the last condition under Else is, implicitly, Age < 18
Example:
If Age >=22 Then
Drink = "Yes"
Else
Drink = "No"
Drink = "Yes"
Else
Drink = "No"
End If
Note that End If statement is needed in this case as well since there is more than one block of statements
The IF ... Then ... ElseIf is used to test additional conditions without using new If ... Then statements.
For Example:
If Age >= 18 and Age < 22 Then
Msgbox "You can vote"
ElseIf Age >=22 and Age < 62 Then
Msgbox "You can drink and vote"
ElseIf Age >=62 Then
Msgbox "You are eligible to apply for Social Security Benefit"
Else
Msgbox "You cannot drink or vote"
End If
Msgbox "You can vote"
ElseIf Age >=22 and Age < 62 Then
Msgbox "You can drink and vote"
ElseIf Age >=62 Then
Msgbox "You are eligible to apply for Social Security Benefit"
Else
Msgbox "You cannot drink or vote"
End If
Note that the last condition under Else is, implicitly, Age < 18
Comments
Post a Comment
jeetexceltips@gmail.com