Allows you to avoid running certain sections of your code
Code is only executed when a condition (or conditions) evaluate to True
Provides a single application the ability to react differently to different input values

Conditional Statements
“If” statement
Single-statement "If"
Multi-statement "If“
"If ... Else" Statement
"If ... ElseIf" Statement
"Select Case" Statements
Performs an operation only if the condition evaluates to True
Used when an action is either performed or not performed.
Performs the If portion only if the condition evaluates to True and the Else portion otherwise.
Used in an either or scenario when an operation is always performed.

Only one section can be executed even if many conditions evaluate to True.
Used in a multiple choice scenario
Inclusion of the last Else is optional
Used to choose between 1 of several discrete values for a variable.
Inclusion of Case Else is optional
Less powerful compared to the If statement
Allows you to repeat running certain sections of your code
Code executes when a condition (or conditions) evaluate to True
Be careful with Loops. They can result in infinite processing.
Entry Condition
Entry only when a initial condition is met
Repeats for a specific number of times
VBScript Loop Statements
"For ... Next" Statements
"While" Statements
"Do ... Loop" Statements
For Loop
Iterated Loop
Favored because all the loop details are in the definition statement

Entry Condition Loop
Simplest form of the loop
Requires manual modification of the loop condition

Do ... Loop
Similar to the while loop.

Arrays - Introduction
Collection of data elements of the same data type.
Each element in an array is associated with a unique index number.
A specific element in an array can be referred by the index number.
A number of built-in functions are provided to work with arrays.


Assigning Values to Array Elements

Retrieving Values from Array Elements

Array - Types
Two Types
Fixed-size array

Dynamic array
Array – Fixed Size
Dim A(10)
All arrays are zero-based.
A(0) = 3 …. A(9) = 6
Array - Dynamic array
Use Dim statement to initialize the array without the size or the number of dimensions.
Dim MyArray()
Subsequently use ReDim to determine the number of dimensions and the size of each dimension.
ReDim MyArray(25)

Use Preserve keyword to preserve the contents of the array.
ReDim Preserve MyArray(30)
Use Erase keyword to release the memory.
There is no limit to the number of times you can resize. But making an array smaller than it was may lose the data in the eliminated elements.


VBScript Procedures
There are two kinds of procedures
Sub procedure

Function procedure
Sub procedures
It is enclosed by Sub and End Sub statements.
Performs actions but don't return a value.
Can take arguments, if no, include an empty set of parentheses ()
Calling the Procedure
It can be called from
Another procedure
Control's event in the body section of an HTML file.

Passing an Argument
Procedure will take values from outside.
These values are called as “Arguments”.
The number and types of arguments of a procedure depends on various factors.

Function procedures
Enclosed by the Function and End Function statements.
Similar to a Sub procedure, but can also return a value.
Can take arguments, if no, include an empty set of parentheses ().
Return a value by assigning a value to its name in one or more statements of the procedure.
The return type of a Function is always a Variant.


It is based on the Visual Basic
Supports object oriented features
It is Interpreted by the browser
Loosely Typed
It is used to create the dynamic and interactive website
In ASP (Active Server Pages) VBScript is used as a server side script language.
Adding VBScript Code to an HTML Page
The SCRIPT element is used to add VBScript code to an HTML page.
VBScript – Language Fundamentals
Syntax Rules
VBScript is not case sensitive (except for Strings)
Each statement can only exist on one line
Statements can be either simple statements or compound statements
‘ (Single quote) – Comment Symbol
Can be a complete line or a portion of a line.
VBScript does not support multi-line comments. The comment symbol must be put at the start of each comment.
Naming Rules
Must begin with a letter or the underscore
valid: count, strInfo, _data
Invalid: 2day, 4get, *count violate this rule.
Cannot contain special characters except the underscore
valid: Names using alphabets, numbers and the underscore.
Invalid: Names using symbols and other special characters.
Naming Rules
Cannot match a reserved word
Example: for, if, Select
Must be unique within a context
Must be less than 256 characters
VBScript Variables and Data Types
Variables hold values that can change during program execution
They function just like temporary storage locations
Declaration of variables is optional, but recommended
The Option Explicit statement is available to require explicit declaration of all variables.

Dim, Public and Private Statements are used to explicitly declare the variables.
Dim variableName
Assigning the Value to the Variable
Dim stud_name – Variable Declaration
stud_name = “Sanjay” – Assigning the value
Constant names hold values that cannot change during program execution
Constants should be used in place of hard-coded values
Const constantName = value
VBScript Data Types
VBScript has only one data type called a Variant which contains either numeric or string information.
VBScript interprets a variant in a manner that is suitable to the type of data it contains.
The different categories of information that can be contained in a Variant are called subtypes.

VBScript Operators
Type of Operators
Arithmetic Operators
Comparison Operators
Logical Operators

Arithmetic Operator
Used to perform calculations
Both operands must be numeric values
The result is a numeric value
Used to compare the value of two items
Both operands must be of the same data type
The result is a Boolean value
Logical Operator
Used to reduce Boolean values into a single Boolean value
Both operands must be Boolean values
The result is a Boolean value