If ... Then ... Else ... End If

Top  Previous  Next

If..Then..Else - Conditional Processing Depending on Result

Language: VBScript

Description
This function is used to execute a set of instructions based on whether certain conditions are found to be true or false.

If...Then
The If...Then function allows you to execute intructions only if a certain condition is met. It is written using the following syntaxes:

If Expression = True Then

   'Execute Instructions

End If

 

or 

 

If Expression Then

   'Execute Instructions

End If

 

You can also check for a false condition using the following statements: 

 

If Expression = False Then

   'Execute Instructions

End If

or

If Not Expression Then

   'Execute Instructions

End If

Else and ElseIf

 
It is possible to extend the process to check for other conditions (ElseIf) or to execute alternate commands if none of the conditions are met (Else) using the following syntax:

If Number = 0 Then

   SMEvent.Raise "Trace", "Number 0"

ElseIf Number = 1 Then

   SMEvent.Raise "Trace", "Number 1"

ElseIf Number = 2 Then

   SMEvent.Raise "Trace", "Number 2"

Else

   SMEvent.Raise "Trace", "Number not 0, 1 or 2"

End If

Note: The If function itself does not evaluate the supplied expression, it instead relies on either receiving a True or False value. Therefore you are able to use whatever variable or expression you choose as long as the result is either true or false.