In the previous chapter, the result of the decision made some action, or nothing to happen. The command can be used to make an alternate action happen as well, which is the norm.
The general form is:
|
If - Then -Else |
| If condition Then … statements Else ... statements EndIf |
Condition controls the outcome and must be a Boolean expression.
An example would be Age < 6.
The following example will demonstrate how this is done.
The Australian Taxation office allows some people to claim use of their private car. Cars which have engine capacities 1500 cc and over are allowed 65c per kilometer travelled, while those with engine capacities up to 1500cc are allowed 45c per kilometer because they are smaller. A program is needed to calculate the allowances.

Get EngineSize Get Kilometers If EngineSize < 1500 Then Set CurrentRate To SmallRate Else Set CurrentRate To LargeRate EndIf Set Allowance To CurrentRate * Kilometers Write Kilometers and Allowance
Private Sub CmdCalculate_Click()
Const SmallRate = 0.3
Const LargeRate = 0.35
Dim strEnginesize, strKilometers as string
Dim EngineSize As Integer
Dim Kilometers As Integer
Dim CurrentRate As Single
Dim Allowance As Currency
strEngineSize = InputBox("Enter the size of the engine (cc)", "Enduro")
Enginesize = cInt(strEngineSize)
strKilometers = InputBox("Enter the number of Kilometers travelled", "Enduro")
Kilometers = cInt(strKilometers)
If EngineSize < 1500 Then
CurrentRate = SmallRate
Else
CurrentRate = LargeRate
End If
Allowance = CurrentRate * Kilometers
MsgBox "The allowance for " & Kilometers & " kilometers is $" & Allowance
End Sub
If the condition is true, the first set of commands are carried out (in this case the CurrentRate is set to the SmallRate). If the condition is fales, the alternate commands are carried out. (CurrentRate is set to the LargeRate)
Author: Mike Leishman
updated: 28 June 1998
edited FDS 27/3/07