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.

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

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

```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

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

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

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.



















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!