If …Then...Else
 


Simple selection executes its instruction(s) when the condition is met, depending on the result of a condition being true or false. If the condition is false, then the entire If statement is skipped.

If [condition] Then

[instruction(s)]

End If

 

If sglTotalAmount > 500 Then
      sglShippingCharge = 0
Else
      sglShippingCharge = 10
End If

 

 

Extended selection with If..Then..ElseIf..

 


If [condition 1] Then


      [instruction(s) 1]


ElseIf [condition 2] Then


      [instruction(s) 2]


ElseIf [condition 3] Then


      [instruction(s) 3]


End If








 

 

Extended selection with If..Then..ElseIf..


If [condition 1] Then



      [instruction(s) 1]


ElseIf [condition 2] Then


      [instruction(s) 2]


ElseIf [condition 3] Then


      [instruction(s) 3]


End If



 


If sglTotalAmount > 500 Then

        sglShippingCharge = 0

ElseIf sglTotalAmount > 300 Then

        sglShippingCharge = 10

ElseIf sglTotalAmount > 0 Then

        sglShippingCharge = 15

End If

 


 

 

Combined Conditions



More than one condition can be tested in If clause.









If (condition 1) Logical Operator (condition 2) Then


(instruction)


End If


If (sglTotalAmount > 100) And (blnLoyalCustomer) Then


sglShippingCharge = 0


End If



In the above example, blnLoyalCustomer is a Boolean data type which contains either True of False as data value. So, if blnLoyalCustomer = True had been executed, blnLoyalCustomer will have True as its value. Therefore, blnLoyalCustomer won't need a comparison operator.


(c) Shilpa Sayura Foundation 2006-2017