If ... Then...Else

Repeat a block of statements.

      If condition Then [Statements] [Else Else-Statements]
      If condition Then
      [ElseIf condition-n] Then
      End If

   condition   An expression that evaluates to True or False

   Statements  Program code to be executed if condition is True

Case sensitivity - the VBScript IF statement will always do a Case-Sensitive comparison:
IF "New York" = "new york" THEN ... will evaluate as false.

To make a comparison Case-insensitive, you can use either the UCase() or LCase() functions:
IF UCase("New York") = UCase("new york") THEN ...


hournow = hour(Time())
If hournow > 12 Then WScript.Echo "Good Afternoon"

Dim strCountry
strCountry = "USA"

If strCountry = "USA" Then
   WScript.Echo "United States of America."
ElseIf strCountry = "CA" Then
   WScript.Echo "Canada."
   WScript.Echo "Some other country."
End If

“You have to learn the rules of the game. And then you have to play better than anyone else” ~ Albert Einstein


Select...Case - Conditional execution of a block of code
Do..Loop - Repeat a block of statements
While...Wend - Conditionally repeat a block of statements
Equivalent in PowerShell: If

Copyright © SS64.com 1999-2017
Some rights reserved