If Else In VBScript W3Schools: Complete Guide With Examples

Logan Jul 13, 2026

If you're exploring Visual Basic Scripting (VBScript) and want to create decision structures, you've likely come across the `If...Then...Else` statement. This is VBScript's way of making decisions and executing code based on certain conditions. Let's dive into this fundamental concept, with examples inspired by the renowned learning platform, W3Schools.

Learning the if, else, elseif Conditional Statements in PHP
Learning the if, else, elseif Conditional Statements in PHP

VBScript uses the `If...Then...Else` structure for conditional expressions, helping you control the flow of your scripts. Here's a basic syntax:

Python If...Elif...Else Statement - PythonForBeginners.com
Python If...Elif...Else Statement - PythonForBeginners.com

The Basic `If...Then...Else` Syntax

Here's the core structure of the `If...Then...Else` statement in VBScript:

C# If and Else
C# If and Else

```vbscript If condition Then ' Code to execute if condition is true Else ' Code to execute if condition is false End If ```

Remember, each condition is separated by the `Then` keyword, and multiple conditions can be combined using `And`, `Or`, and `Not` operators.

Single If Condition

Better Software Without If-Else
Better Software Without If-Else

Let's start with a simple example from W3Schools: checking if a number is positive.

```vbscript num = 10 If num > 0 Then Wscript.Echo num & " is positive" Else Wscript.Echo num & " is not positive" End If ```

In this script, the message "10 is positive" will be displayed because the number 10 is greater than 0.

If-ElseIf-Else Structure

PHP Shorthand If ElseIf Else with Example Code
PHP Shorthand If ElseIf Else with Example Code

Sometimes, you might need multiple conditions. VBScript supports an `If-ElseIf-Else` structure for this purpose. Here's an example that categorizes numbers into positive, negative, or zero:

```vbscript num = -5 If num > 0 Then Wscript.Echo num & " is positive" ElseIf num < 0 Then Wscript.Echo num & " is negative" Else Wscript.Echo num & " is zero" End If ```

In this script, the message "-5 is negative" will be displayed because the number -5 is less than 0.

Nesting If...Then...Else Statements

TypeScript - If Statement
TypeScript - If Statement

VBScript allows nesting `If...Then...Else` statements to create complex decision structures. Here's an example that combines single `If` conditions with `If-ElseIf-Else`:

```vbscript num = 15 If num > 0 Then If num > 10 Then Wscript.Echo num & " is greater than 10" Else Wscript.Echo num & " is not greater than 10" End If Else Wscript.Echo num & " is not positive" End If ```

In this script, the message "15 is greater than 10" will be displayed because 15 is both positive and greater than 10.

Part 2: Stop Using If-Else Statements
Part 2: Stop Using If-Else Statements
File Handling in VB.net – IO Classes, FileStream Class in VB.net
File Handling in VB.net – IO Classes, FileStream Class in VB.net
some type of text on a black background
some type of text on a black background
How to do Uppercase and Lowercase in Visual Basic.NET (VB.Net)
How to do Uppercase and Lowercase in Visual Basic.NET (VB.Net)
two screenshots with the same text on them, one has an email message
two screenshots with the same text on them, one has an email message
the writing process is written on a piece of paper with colored arrows pointing in different directions
the writing process is written on a piece of paper with colored arrows pointing in different directions
the words are written in different languages and have been altered to make them appear like they were
the words are written in different languages and have been altered to make them appear like they were
if else in vbscript w3schools
if else in vbscript w3schools
Spelling
Spelling
60K views · 710 reactions | Verb   #reelsvideoシ #reelsviralシ #reelsviralシfb #job #viralreels #reelsfypシ #trendingreels #reelsviral #reelschallenge #foryouシ | Job English
60K views · 710 reactions | Verb #reelsvideoシ #reelsviralシ #reelsviralシfb #job #viralreels #reelsfypシ #trendingreels #reelsviral #reelschallenge #foryouシ | Job English
an image with the words bold and static text below it in different font styles,
an image with the words bold and static text below it in different font styles,
New in beta 2
New in beta 2
i.e. vs e.g. | Difference & Examples
i.e. vs e.g. | Difference & Examples
a table with two different types of english words and the same number of words in each column
a table with two different types of english words and the same number of words in each column
an email form with the words'allevate to make something less severe '
an email form with the words'allevate to make something less severe '
Learn English & IELTS Fast with Weekly Worksheets | Kids + Beginners 📚
Learn English & IELTS Fast with Weekly Worksheets | Kids + Beginners 📚
a poster with the words v2 v3 form of win in english and spanish
a poster with the words v2 v3 form of win in english and spanish
How to Make Text Auto Size in Textbox Using VB.Net?
How to Make Text Auto Size in Textbox Using VB.Net?
the words complex are written in two different languages, and each has an image on it
the words complex are written in two different languages, and each has an image on it

Select Case Statement

VBScript also offers a `Select Case` statement, which is an alternative to multiple `If-ElseIf-Else` conditions. It's particularly useful when you have several conditions testing the same expression. Here's an example checking the value of a variable `grade`:

```vbscript grade = "A" Select Case grade Case "A", "B" Wscript.Echo "Pass" Case "C", "D" Wscript.Echo "Warning" Case Else Wscript.Echo "Fail" End Select ```

In this script, the message "Pass" will be displayed because grade is either "A" or "B".

Mastering `If...Then...Else` structures is crucial for writing efficient and flexible VBScript code. So, practice these examples and experiment with your own conditional expressions. Happy scripting!