Commonly Used Types of Statements

This section provides a list of commonly used types of statements. Simple examples of statements are also provided.

Like any other generic programming language, VBScript offers a number of statement types. I will only list some commonly used statement types below:

"=" (Assignment) Statement - Assigning values to variables. For example:

   author = "Herong"
   price = 9.99

"Call" Statement - Calling a function or a subroutine. For example:

   Call document.writeln("Hello world!")

"Dim" (Declaration) Statement - Declaring variables. For example:

   Dim Author, Title, Size
   Dim Price

"Do ... Loop" Statement - Repeating a block of statements on a Boolean condition. For example:

   Do While i < 10
      sum = sum + i
      i = i + 1
   Loop

"Exit" Statement - Terminating a loop, a function or a subroutine. For example:

   Do While True
      sum = sum + i
      i = i + 1
      If i > 9 Then
         Exit Do 
      End If
   Loop

"For Each ... Next" Statement - Repeating a block of statements on each element of an array. For example:

   list = Array(1,2,3,4,5,6,7,8,9)
   For Each i In list
      sum = sum + i
   Next

"For ... Next" Statement - Repeating a block of statements on each value of an incremental index. For example:

   For i = 1 To 9
      sum = sum + i
   Next

"Function" Statement - Defining a function procedure. For example:

   Function sqrt(x)
      sqrt = x^0.5
   End Function

"If" Statement - Executing a statement or a block of statements conditionally. For example:

   If Weekday(Date())=vbSunday Then message = "We are closed today!"

"Rem" Statement - Writing an explanatory remark. For example:

   Rem The following function returns the square root of x
   Function sqrt(x)
      sqrt = x^0.5
   End Function

"While" Statement - Repeating a block of statements on a Boolean condition. For example:

   While i < 10
      sum = sum + i
      i = i + 1
   Wend

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

 What Is a Statement?

Commonly Used Types of Statements

 Array Data Type and Related Statements

 Array References and Array Assignment Statements

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

 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

 PDF Printing Version