Repeat a block of statements.
Syntax If condition Then [Statements] [Else Else-Statements] or If condition Then [Statements] [ElseIf condition-n] Then [Statements] [Else] [Statements] End If Key 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 ...
Examples
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." Else 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
Related:
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