Home NT WSH
VB Script Conditional Operators

Conditional Statements

If...Then...Else

    If IntMyInteger < 25 Then StrMyTextString = "Insufficent credit"

Block syntax - to run multiple line commands.

   If IntMyInteger < 25 Then
      StrMyTextString = "Insufficent credit"
      AlertLabel.ForeColor = vbRed
   End If

Block syntax - with an Else clause

   If IntMyInteger < 25 Then
      StrMyTextString = "Insufficent credit"
      AlertLabel.ForeColor = vbRed
   Else
      StrMyTextString = "Credit OK"
      AlertLabel.ForeColor = vbBlue
   End If

Adding ElseIf clauses expands the functionality of the
If...Then...Else statement

For example: 

   If IntMyInteger = 0 Then
      MsgBox StrMyTextString0
   ElseIf IntMyInteger = 1 Then
      MsgBox StrMyTextString1
   Else
      Msgbox "Value out of range!"
   End If

Select Case
   This works in a similar way to If...Then...ElseIf 
   but only evaluates the expression once.
   
   Select Case IntMyInteger
      Case 0
         MsgBox StrMyTextString0
      Case 1
         MsgBox StrMyTextString1
      Case 2
         MsgBox StrMyTextString2
      Case Else
         MsgBox "Value out of range!"
   End Select

"Success is 99 percent failure" - Soichiro Honda



Back to the Top

Simon Sheppard
SS64.com