Using VBScript in ASP Pages

This section describes 3 ways to use VBScript codes in ASP pages: in-line statement, in-line expression, and statement block.

There are three ways to use VBScript in ASP pages:

1. In-line VBScript statements: The VBScript statements must be enclosed in the special in-line script tag: <% %>. The enclosed statements will be executed by the server, and the output of response.write() calls will be merged in-line with the surrounding static HTML text. In-line VBScript statements require a language declaration statement to define explicitly VBScript as the server side scripting language, if you are not sure what is the default language defined on the Web server.

<%@ language="vbscript"%>
...
<%
vbscript_statement
vbscript_statement
...
%>

2. In-line VBScript expression: The VBScript expression must be enclosed in the special in-line script tag: <% %> with a leading "=" sign. The enclosed expression will be evaluated, and the resulting value will be converted into a string and merged in-line with the surrounding static HTML text. In-line VBScript expression also require a language declaration statement to define explicitly VBScript as the server side scripting language, if you are not sure what is the default language defined on the Web server.

<%@ language="vbscript"%>
...
<%
= vbscript_expresion
%>

3. Script block of VBScript statements: The VBScript statements must be enclosed by the starting script block tag <script> and the ending tag </script>. Two attributes are required on the script tag: "language" and "runat".

<script language="vbscript" runat="server">
vbscript_statement
vbscript_statement
...
</script>

Please note that the script block VBScript statements will be executed by the server. But the output of response.write() calls will not be merged in-line with the surrounding static HTML text. It will be:

This rule was a big surprise to me. I had to post a message to microsoft.public.inetsdk.programming.scripting.vbscript, and got confirmed from Microsoft. See the article Using VBScript and JScript on a Web Page.

Last update: 2003.

Table of Contents

 About This Book

 ASP (Active Server Pages) Introduction

 IIS (Internet Information Services) 5.0

 MS Script Debugger

VBScript Language

Using VBScript in ASP Pages

 Mixing VBScript Statements with Static HTML Text

 Variables and Expressions in VBScript

 Arrays and Loops in VBScript

 "Collection" Class in VBScript

 ASP Built-in Run-time Objects

 ASP Session

 Creating and Managing Cookies

 Managing Sessions with and without Cookies

 scrrun.dll - Scripting Runtime DLL

 Managing Response Header Lines

 Calculation Speed and Response Time

 ADO (ActiveX Data Object) DLL

 Working with MS Access Database

 Guest Book Application Example

 References

 PDF Printing Version