Using VBScript with Internet Explorer

This section provides tutorial example on how to embed a VBScript code in a HTML document to be executed by Internet Explorer on the client machine.

Internet Explorer (IE) is a Microsoft application that can be used a Web browser to view Web pages. IE also supports a VBScript host environment that allows you to embed VBScript codes into source codes of Web pages - HTML documents.

VBScript codes embedded in HTML documents will be executed while IE is rendering HTML documents on the browser window. This is also called client side scripting, because script codes are executed on the client machine instead of the server machine.

To add VBScript codes into your HTML documents, you need to use the "script" tag with the "language=vbscript" attribute. Inside the "script" tag, you can place any number of VB statements. Here is the syntax of adding VBScript codes in HTML documents:

... (HTML tags)
<script language=vbscript>
   ... (VB statements)
</script>
... (HTML tags)

Now let's try to write our first VBScript code in a HTML document.

1. Open the Notepad to enter the following HTML document:

<html>
<body>
<script language="vbscript">
   document.write("Hello world! - VBScript in IE")
</script>
</body>
</html>

2. Save the HTML document as hello_vb.html.

3. View the HTML document with IE. You should see the following message in the IE window:

Hello world! - VBScript in IE

Congratulations. You have successfully written a VBScript code for the host environment supported in IE!

What happened here was:

Table of Contents

 About This Book

Introduction of VBScript - Visual Basic Scripting Edition

 What Is VBScript?

Using VBScript with Internet Explorer

 Using VBScript with Internet Information Services

 Using VBScript with Windows Script Host

 Using Visual Basic with Microsoft Access

 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"

 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