VBScript Tutorials - Herong's Tutorial Examples - Version 5.20, by Dr. Herong Yang

"If" Statements

This section describes 4 forms of 'If' statements supported in VBScript. The more complex form is 'If ... ElseIf ... Else ... End If'.

There are 4 forms of "If" statements supported in VBScript:

1. Single-statement "If":

   If condition Then statement

where "condition" is Boolean value, and "statement" specify another statement. The specified statement will be executed, if and only if the specified condition is evaluated to "True".

2. Multi-statement "If":

   If condition Then 
      statement_block (multiple statements)
   End If

The specified multi-statement block will be executed, if and only if the specified condition is evaluated to "True".

3. "If ... Else" Statement:

   If condition Then
      statement_block_a
   Else
      statement_block_b
   End If

Two statement blocks are specified. But only one statement block will be executed based on the value of the specified condition. If the specified condition is "True", the first block will be executed. If the specified condition is "False", the second block will be executed.

4. "If ... ElseIf" Statement:

   If condition_1 Then
      statement_block_1
   ElseIf condition_2 Then 
      statement_block_2
   ...
      ...
   Else
      statement_block_n
   End If

Many statement blocks are specified. But only one statement block will be executed based on the value of the condition specified for that block.

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 Numeric Comparison Operations and Logical Operations

 String Operations - Concatenation and Comparison

 Variable Declaration and Assignment Statement

 Expression and Order of Operation Precedence

 Statement Syntax and Statement Types

 Array Data Type and Related Statements

 Array References and Array Assignment Statements

Conditional Statements - "If ... Then" and "Select Case"

"If" Statements

 "If" Statement Examples

 "Select Case" Statements

 "Select Case" Statement Examples

 Loop Statements - "For", "While", and "Do"

 "Function" and "Sub" Procedures

 Built-in Functions

 Inspecting Variables Received in Procedures

 Error Handling Flag and the "Err" Object

 Regular Expression Pattern Match and Replacement

 scrrun.dll - Scripting Runtime DLL Library

 Creating Your Own Classes

 IE Web Browser Supporting VBScript

 IIS ASP Server Supporting VBScript

 WSH (Windows Script Host)

 References

 Printable Copy - PDF Version

"If" Statements - Updated in 2015, by Dr. Herong Yang