Skip to main content.

Web Based Programming Tutorials

Homepage | Forum - Join the forum to discuss anything related to programming! | Programming Resources

Web Programming Desktop Reference 6in1

Chapter 27 -- Understanding the Visual Basic Script Reference Section

Chapter 27

Understanding the Visual Basic Script Reference Section


This section is a reference guide to the concepts, statements, and objects of Visual Basic Script. It is not an introduction to the language. Quick references are designed to sit on your programming desk so that you can easily look up a forgotten spelling or some procedure's parameter that you are unsure of.

This book assumes that you have a working knowledge of HTML. You need to know HTML because all VBScript programs reside inside HTML documents. If you are not familiar with HTML, please read Que's HTML by Example.

Using This Reference

Several conventions used in this book make finding information easier. Several entries contain tables that point you off to other entries. This was done so that the information did not need to be listed twice. For example, the section on variables briefly discusses the nature of variables and then lists the variable types. Each variable type has its own entry.

Each entry has the same basic structure. First, the type and syntax are presented. Then a one-line description (the synopsis) and the parameters are discussed. Next come the description, example, figure, and see also sections. All of these elements are optional and only appear if the entry needs it.

The syntax description follows several guidelines. Italicized items need to be replaced with actual values or variable names. Optional items are surrounded by square brackets ([]). If an entry has more than one form of syntax, more than one syntax element will be present. In this case, the syntax elements are numbered to indicate the different forms.

What is VBScript?

This section briefly covers some vital information that you need to know before you can successfully create VB scripts.

VBScript is used with HTML pages to increase functionality and interaction with the end user. The language currently has no other purpose other than to enhance Web documents.

VBScript is essentially a subset of the full Visual Basic language; if you already know Visual Basic, then you can safely say that you know VBScript.

VBScript is not case-sensitive. This means that a function called SendAlert is the same as one called sendAlert.

All VBScript statements are contained inside HTML <SCRIPT> tags or inside form element tags. VBScript statements are executed when the HTML document is loaded or in response to some event that happens in the browser's window.

When the document is loaded, any VBScript statements that are not inside procedures are executed. If you have variables to declare or other initialization statements, place them inside a <SCRIPT> tag inside the header section (the <HEAD> and </HEAD> tags) of the document. Procedures must be defined before they can be used, therefore it's a good idea to place procedure definitions inside the header section also. Placing initialization statement and procedure definitions in the header section makes the body of the document less cluttered.

Listing 27.1 shows a very simple example of how VBScript programs are used. The and VBScript statements in the <SCRIPT> tag are not associated with any events and are executed as soon as the Web browser reads the statements. You can prove this by noticing that the phrase "This is a test." appears before the "VB Script Example Page" header in Figure 27.1.

<TITLE>VB Script Example Page</TITLE>
document.write "This is a test."

Sub sendAlert (msg)
Alert msg
End Sub
<H1>VB Script Example Page</H1>
<INPUT NAME=btnLaugh OnClick=sendAlert("HA-HA!")
TYPE=button VALUE="Want a laugh?">

Figure 27.1: This is what Listing 27.1 looks like when displayed in Internet Explorer.

The reference section has several dictionary-type entries that you may want to look at. These entries are listed in Table 27.1.

Table 27.1  Dictionary Entries

Conversion Functions
Date/Time Functions
Event Handling
Literal Values
Math Functions
Object Variables
Operator Precedence
String Functions
Type Conversion
Variant Testing Functions
VBScript Statements

Differences Between VBScript and Visual Basic

There are quite a few differences between VBScript and Visual Basic. The most notable difference is that VBScript needs a Web browser in order to execute, whereas VB programs can be stand-alone executables.

If you don't know Visual Basic, skip this section. However, if you are already proficient in Visual Basic, you need to be aware of VBScript's limitations so that you don't waste time trying to do things that aren't possible. While some of the functionality of Visual Basic forms can be duplicated using HTML forms and ActiveX Controls, you'll find that some aspects of your applications will be hard to implement in VBScript.

Table 27.2 lists the limitations that VBScript has in relation to Visual Basic. Most of the limitations are due to security or memory considerations. In addition, VBScript is designed to enhance HTML documents, not to perform transaction processing or file access.

Table 27.2  VBScript's Limitations

Array HandlingVBScript does not support the Array function, the Option Base statement, or declaring arrays with a lower bound different from zero.
ClipboardNot supported.
CollectionNot supported.
Conditional CompilationNot supported.
ConstantsNot supported. However, you can emulate constants by assigning values to variables in the header section of the HTML document and then not changing them.
Control FlowThe following control statements are not supported: DoEvents, For Each...Next, GoSub...Return, GoTo, On Error GoTo, On...GoSub, On...GoTo, Line Numbers, Line Labels, and With...End With.
Data ConversionThe following data conversion functions are not supported: CCur, CVar, CVDate, Format, Str, and Val.
Data TypesVBScript only supports one data type called Variant. However, you can use many different subtypes. In addition, the Type...End Type statement is not supported.
Date/TimeThe Date and Time statements and the Timer function are not supported.