Visual Basic Script for Dummies


If you're used to the bells and whistles that make CD-ROM multimedia titles so exciting, you may find plain 'ol HTML Web pages limiting. Luckily, you can overcome these limitations by using Microsoft's VBScript programming language to spice up the interactivity and functionality of the Web pages you create. VBScript For Dummies puts the power of this programming language in your hands -- even if you've never programmed before. With best-selling author John Walkenbach to guide you, you discover how to embed ...
See more details below
Available through our Marketplace sellers.
Other sellers (Paperback)
  • All (5) from $24.69   
  • New (1) from $129.18   
  • Used (4) from $24.69   
Sort by
Page 1 of 1
Showing All
Note: Marketplace items are not eligible for any coupons and promotions
Seller since 2008

Feedback rating:



New — never opened or used in original packaging.

Like New — packaging may have been opened. A "Like New" item is suitable to give as a gift.

Very Good — may have minor signs of wear on packaging but item works perfectly and has no damage.

Good — item is in good condition but packaging may have signs of shelf wear/aging or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Acceptable — item is in working order but may show signs of wear such as scratches or torn packaging. All specific defects should be noted in the Comments section associated with each item.

Used — An item that has been opened and may show signs of wear. All specific defects should be noted in the Comments section associated with each item.

Refurbished — A used item that has been renewed or updated and verified to be in proper working condition. Not necessarily completed by the original manufacturer.

0764500309 New. Looks like an interesting title!

Ships from: Naperville, IL

Usually ships in 1-2 business days

  • Standard, 48 States
  • Standard (AK, HI)
Page 1 of 1
Showing All
Sort by
Sending request ...


If you're used to the bells and whistles that make CD-ROM multimedia titles so exciting, you may find plain 'ol HTML Web pages limiting. Luckily, you can overcome these limitations by using Microsoft's VBScript programming language to spice up the interactivity and functionality of the Web pages you create. VBScript For Dummies puts the power of this programming language in your hands -- even if you've never programmed before. With best-selling author John Walkenbach to guide you, you discover how to embed VBScript programs into your HTML pages, exploit Microsoft Internet Explorer's object-oriented features, orchestrate multiple frames, and make use of ActiveX controls. Plus, on the book's accompanying bonus disk, you get all the examples presented in the book -- ready for you to experiment with and adapt for your own use.

Read More Show Less

Product Details

  • ISBN-13: 9780764500305
  • Publisher: Wiley, John & Sons, Incorporated
  • Publication date: 7/12/1996
  • Series: For Dummies Series
  • Edition number: 1
  • Pages: 408
  • Product dimensions: 7.42 (w) x 9.28 (h) x 1.11 (d)

Table of Contents

So, You Want to Be a Programmer . . .
What This Book Covers
What This Book Doesn't Cover
How This Book Is Organized
Part I: What's It All About?
Part II: How VBScript Works
Part III: Programming Concepts
Part IV: Doing Useful Stuff
Part V: Incorporating ActiveX Controls
Part VI: Putting It All Together
Part VII: The Part of Tens
Assumptions About You
VBScript: New Language, Old Friend
What You Can Do With VBScript
Marginal Icons
The Web Site On a Disk
And More!
Wanna Reach Out?
Now What?
Part I: What's It All About?
Chapter 1: What You Need and Where to Get It
Your Basic Needs
Just Where Is VBScript?
Surfing for Downloads
Internet Explorer 3.0
ActiveX Control Pad
ActiveX Controls
Ladies and Gentlemen . . . Choose Your Editor
Windows Notepad
Windows WordPad
Microsoft Word, with Internet Assistant
More HTML editors
Getting Ready to Script
A Sneak Preview
Chapter 2: Your First VBScript Program (A Script-Tease)
What You Do
Create the HTML Document
Adding the Buttons
Inserting the Script
Creating the basic subroutine
Modifying the subroutine
Adding the second subroutine
The final document (Take 1)
Testing the script
Making changes (Take 2)
Taking a closer look
The problem
Fixing the bug (Take 3)
Part II: How VBScript Works
Chapter 3: Exploring the Explorer (Internet Explorer 3.0, That Is)
Excursions Into Versions
Cool Browser . . . Very Cool
Internet Explorer innovations
What about compatibility?
Internet Explorer Features You May Have Missed
Parts of Internet Explorer
Your window on the World (Wide Web)
I've been framed!
The well documented document
What's your location?
Don't know much about history . . .
Chapter 4: Using Scripts in Your HTML Documents
Including VBScript in HTML Documents
Direct execution of VBScript
Deferred execution by using a VBScript procedure
Understanding the <SCRIPT> Tag
Match 'em up
How many script blocks?
Where to put scripts
The LANGUAGE attribute for <SCRIPT>
What about older browsers?
Writing VBScript Code
Using comments in VBScript code
Upper- or lowercase?
Indenting and spaces
Splitting a statement into two or more lines
Hey! That's Private!
Compatibility Issues
When to use VBScript
When to avoid VBScript
VBScript versus JavaScript
Chapter 5: Introducing Objects and the Object Model
The Object Model Visualized
The Collection Plate
Referring to Objects
How Objects Relate to Internet Explorer Features
A concrete example
A way to conceptualize objects
A family affair
Drilling Deeper into the Object Model
The Objects Described
The Window object
The Frame object and the Frames collection
The History object
The Navigator object
The Location object
The Script object
The Document object
The Link object and the Links collection
The Anchor object and the Anchors collection
The Form object and the Forms collection
The Element object and the Elements collection
Chapter 6: All about Properties, Methods, and Events
Making Objects Useful
Examining Object Properties
Referring to properties
Looking at property values
Changing property values
Pointing to objects
Seeing the Document object properties in action
Exploring Object Methods
Understanding Object Events
Handling those events
An event-handling example
Finding Out More about This Stuff
Part III: Programming Concepts
Chapter 7: All about Subroutines and Functions
Procedural Matters
Looking at subroutines
Looking at functions
Subroutine Examples
An event handler example
A subroutine with an argument
How it works
Another way to do it
Calling a Subroutine from Another Subroutine: Rules of the Road
Calling a subroutine with no arguments
Calling a subroutine with an argument
Function Examples
A simple function example
The ReverseText function
Where to Put Your Procedures
A bad example
A good example
Troubleshooting Subroutines and Functions
Chapter 8: Using Variables and Arrays
Introducing Variables
Naming variables
Bad variable names
Today's Assignment . . .
Express yourself
Hello, Operator . . .
Common operators
Logical operators
What gets calculated first?
Order of precedence
Parentheses to the rescue
Array of Hope
Well, I declare!
Multidimensional arrays
Dynamic arrays
How many elements?
Scoping Variables and Arrays
Broadening a variable's scope
Declaring multiple variables
Object Variables: A Special Type
Forcing Variable Declaration
How to force yourself to declare all variables
Why force yourself to declare all variables?
Chapter 9: Controlling Program Flow and Decision-Making
Go with the Flow, Dude
If-Then Structure
Examples of conditions
If-Then examples
If-Then with multiple instructions
Supplying an Alternative: If-Then-Else
If-Then-Else with multiple instructions
Another option: If-Then-ElseIf
The Select Case Structure
A Select Case example
A catch-all case
Nested Select Case structures
Looping de Loops
For-Next Loops
A For-Next example
A For-Next example with a step value
Looping backwards
For-Next and arrays
A nested For-Next example
Do Until Loops
Do While Loops
Do-Loop Until Loops
Do-Loop While Loops
Cheat Sheet For Looping
Chapter 10: Getting Acquainted with Built-In Functions
Using Functions in Your Code
Functions Galore
Function Examples
Conversion functions
The Chr function
The Asc function
The Hex function
The Int and Fix functions
Date and time functions
Current date and time functions
Nesting date and time functions
Weekday function
Math functions
Trigonometric functions
Random number functions
String functions
The Mid function
The Left and Right functions
The Lcase and Ucase functions
The Len function
The Instr function
Variant functions
The IsDate function
The IsNumeric function
User Interface functions
The InputBox function
Finding out More about Functions
Chapter 11: Correcting Errors and Exterminating Bugs
Make an Error? Me?
Syntax Errors
Anatomy of a syntax error message
Avoiding syntax errors
Entomology 101: Program Bugs
Runtime errors
Logical flaws
Identifying Bugs
Avoiding Error Messages
Stomping Those Bugs
Examining your code
Using Alert statements
Monitoring a variable
Bug Prevention Tips
Develop your code in small bits
Force variable declaration
Use consistent indentation
Remember a variable's scope
Test extreme cases
Let others test your code
Test your code on the server
Part IV: Doing Useful Stuff
Chapter 12: Working With the HTML Intrinsic Controls
HTML Intrinsic Controls: What's Available?
Button Controls
Displaying a message
Changing a button caption
Opening a new URL
Simulating the Back and Forward buttons
Submit and Reset Controls
Text Controls
Using a text control for input
Using a text control for output
Understanding the OnFocus and OnBlur events
Textarea Control
Password Control
Radio Button Controls
Executing a subroutine when a radio button is clicked
Determining which radio button is selected
Check Box Control
Select Control
Which item is selected?
Determining multiple selections
Hidden Control
Chapter 13: Working with Forms
Read Me First!
HTML Forms: A Refresher Course
Defining a form
Adding form controls
Validating a form
VBScript and HTML Forms: A Winning Combination
Referring To Controls
Referring to a control by its position in the form
Referring to a control by name
An example
Using object variables
Generating Forms and Controls With VBScript
Generating alphabet radio buttons
Generating a list of numbers
Generating a list of dates for the current month
Client-Side Data Validation
What gets validated?
The OnSubmit event
Validating a form: Example one
Validating a form: Example two
Using Form Controls For a Link List
Chapter 14: Working with Frames
Frames: Not Just For Pictures Anymore
A Frame Example
Referring to a different frame
Other ways to refer to a frame
Still confused?
Another Frame Example
Using a button to load a URL into a different frame
Loading a URL into a different frame using a hyperlink
Changing the colors in a different frame
More Ways to Load Documents
Loading a document in another frame
Loading a new document in the current frame
Loading a document in the browser's full window
Loading a document in a new browser window
Floating Frames
Updating a page dynamically with a floating frame
The HTML document
How it works
A more sophisticated borderless frame example
Fun With Floating Frames
Simple animation effects
A VBScript message flasher
Message flasher code
Customizing the message flasher
Frame animation -- big time!
Chapter 15: Useful Code Snippets That You Can Steal
Number Formatting Functions
Formatting dollars and cents
Formatting percentages
Spelling out numeric values
Displaying a Friendly Date and Time
Converting Hex to Decimal
Detecting a VBScript-Compatible Browser
Audio Greeting Based on the Time of Day
Validating a Credit Card Number
A Scrolling Status Bar Message
Special FX
Background fade-in
Sorting an Array
Choosing Lottery Numbers
Part V: Incorporating ActiveX Controls
Chapter 16: ActiveX Controls: What, Where, and Why
Okay, So What Is an ActiveX Control?
Two quick examples
An ActiveX Label control
An ActiveX ScrollBar control
Where Do You Get ActiveX Controls?
Types of controls
ActiveX controls from Microsoft
Microsoft Forms 2.0 controls
Other Microsoft ActiveX controls
Other sources for ActiveX controls
The Technology Behind the Magic
Downloading a control
Security for controls
Using ActiveX Controls: Pros and Cons
The Pros
The cons
Chapter 17: Using ActiveX Controls: The Gory Details
The OBJECT Tag: It Gets Ugly
An example OBJECT tag
The OBJECT tag attributes
The PARAM tags
Introducing the ActiveX Control Pad
HTML text editor
ActiveX Control editor
Script Wizard
HTML Layout editor
Hands-On: Using the ActiveX Control Pad
Creating a new document
Inserting an ActiveX Label control
Changing Label control properties
Inserting an ActiveX SpinButton control
Adding HTML
Viewing the document
Using the Script Wizard
Testing the script
More about the Script Wizard
Discovering Properties and Methods
ActiveX Examples
The ActiveX Marquee control
The ActiveX PopUp Menu control
The ActiveX ButtonMenu control
The ActiveX Timer control
Another ActiveX Timer control example
Yet another ActiveX Timer control example
Using ActiveX controls in HTML forms
Chapter 18: The Coolest Control: The HTML Layout Control
The HTML Layout control
The upside of the HTML Layout control
The downside of the HTML Layout control
An Introductory Example
Using the example
Looking at the OBJECT tag
About ALX files
Hands-On: Creating a Layout
1. Creating the HTML File
2. Inserting a Layout control
3. Saving the HTML file
4. Editing the HTML Layout
5. Adding the Image control
6. Adding a Label control
7. Adding a HotSpot control
8. Writing the VBScript
9. Testing the subroutine
10. Finishing off the subroutine
Discovering More about the HTML Layout Control
Layout Control Examples
Watch the bouncing balls
Rolling the dice
Using ListBox controls
Part VI: Putting It All Together
Chapter 19: Creating Column Charts with VBScript
What is a Column Chart?
Using graphic files
A cool chart-making technique
Creating a Chart with VBScript
The code behind the magic
How the code works
Creating a Chart in a Frame
Creating the floating frame
Creating the chart
Trying out the chart example
Scaling the chart
Getting Even Fancier
Declaring the variables
Generating the select controls
Generating the chart
Adapting These Techniques
Chapter 20: Calculating Mortgage Payments
Project Goals
The Game Plan
Creating the Forms
The data input form
The results form
Calculating the Results
The On_Click subroutine
How the subroutine works
Calculating the monthly payment
Formatting the numbers
Amortizing the Loan
Inserting a floating frame
Adding another button
Calculating the amortization schedule
The Amortize_OnClick subroutine
How the subroutine works
Testing the subroutine
A change of plans
Chapter 21: Creating a Calendar Application
Project Background
The Game Plan
Specifying a Month and Year
Inserting the ActiveX controls
Creating an array of month names
Adding a Window_OnLoad subroutine
The event handlers
Testing the controls
Developing the Calendar
Adding a floating frame
Sending HTML to the frame
Calling the GenerateCalendar subroutine
Testing it again
Adding the Links
Creating an array
Displaying the tour information
Creating the links
Trying out the code
Making It Look Good
Chapter 22: Administering an Online Quiz
Project Goals
The Game Plan
Project Components
Storing the Data
Presenting the Items
How the Application Works
Creating Your Own Quiz
Part VII: The Part of Tens
Chapter 23: Top Ten VBScript Questions and Answers
Is VBScript the same as Visual Basic?
Where can I get a copy of the VBScript programming language?
What are the typical uses for VBScript?
If I use VBScript in my Web document, is the number of people who can access my site limited?
If a user accesses my Web site with a VBScript compatible browser, can the browser automatically load a different VBScript enhanced page?
I use VBScript on my Web site to perform proprietary calculations. How can I prevent my competitors from viewing my VBScript code?
When a user loads my page, how do I execute a program that's on the user's local drive?
When I visit a site that uses VBScript, I like to look at the source code. But if the site uses frames, I find that the View-->Source command only shows the top level frame. What gives?
Can I set up a Web page hit counter using VBScript?
Chapter 24: Top Ten VBScript Resources on the Net
The Microsoft VBScript Site
The VBScript Mailing List
VBScript Newsgroups
VBScript Central
The VBScript / ActiveX Demo Page
Scribe: The VBScript Writers Resource
ActiveX Journal for HTML Writers
ActiveX Resource Center
Web search engines
Chapter 25: Top Ten Ways to Become a VBScript Guru
Browse the Web
Look at a Lot of VBScript Code
Communicate with Others
Borrow and Adapt Others' Ideas
Study the Documentation
Study the Examples in this Book
Think like a Web Site Visitor, Not a Designer
Think Modular
Experiment More
Read More Show Less

First Chapter

Chapter 4
Using Scripts in Your HTML Documents

In This Chapter

  • Three ways to include VBScript in your Web page
  • Everything you need to know about the <SCRIPT> tag
  • The mechanics of entering VBScript code
  • Compatibility issues: When to use VBScript and when to avoid using it
  • How to protect your code from prying eyes -- not!
  • What happens when you load an HTML document into Internet Explorer

When you write VBScript, the code is inserted, or embedded, directly into an HTML document. This chapter discusses the mechanics involved in embedding scripts into HTML documents.

Including VBScript in HTML Documents

VBScript can be included in your Web page in two ways:

  • Directly (an immediate script)
  • As a subroutine or function procedure (a deferred script)

Direct execution of VBScript

One way to include VBScript in your document is to insert it directly into your HTML code. The script must be embedded between a <SCRIPT>and a </SCRIPT> tag. When the document is loading, Internet Explorer executes the script and follows your instructions.

The following example is an HTML document with embedded VBScript code:

<H1>Sample Document</H1>
Hello, and thanks for dropping by.
In case you're wondering, this HTML document was last updated on
Document.Write Document.LastModified
Document.Write "."
Please visit again!

Figure 4-1 shows how the document looks in the browser.

This example is a standard HTML file. The only unusual part is the text between the <SCRIPT> and </SCRIPT> tags. That text, as you've probably deduced by now, is VBScript code.

When the browser loads this document, it encounters the <SCRIPT> tag and switches over to the VBScript interpreter, which executes the statements. In this case, the statements write text directly to the document. The text consists of the date and time the document was modified (first line of code) and a period (second line of code). Then, the </SCRIPT> tag signals the end of the script, and the browser finishes displaying the document.

Note: At this juncture, you don't need to understand the code. The point is to demonstrate various ways of inserting VBScript into a document.

This type of script is sometimes called an immediate script because it is executed immediately as the page is being loaded and interpreted by the browser. Such scripts are useful because they can create dynamic content. For example, you can use an immediate script to include the current date and time, display the contents of a cookie, or generate special text effects.

These immediate scripts execute only once, when the page loads, and cannot be executed by other events, such as button clicks. If you need to execute VBScript code more than once, it must be placed in a procedure (which I discuss in the next section).

Deferred execution by using a VBScript procedure

In the previous section, I discuss immediate scripts, which is one way to insert VBScript into a Web document. The second way to insert VBScript into your documents is to use a procedure. VBScript procedures come in two types: subroutines and functions (see Chapter 7, if you're unsure of the difference between the two).

The following example is an HTML document that has VBScript coded as a subroutine. The subroutine is named MyButton_OnClick, and it consists of a single line of code:

<H1>Sample Document</H1>
Hello, and thanks for dropping by. Click the button to find out when this document was last updated.
<INPUT TYPE=Button NAME=MyButton VALUE="Click Me">
Please visit again!
Sub MyButton_OnClick ()
Alert Document.LastModified
End Sub

Figure 4-2 shows how this page looks when displayed in a browser. When you click the button, a small dialog box displays the date and time when the document was last modified.

Unlike the previous example, this script does not execute when the document loads. This type of script is sometimes known as a deferred script. The only way this script executes is when a particular event calls it. In this case, clicking the button is the event that calls the subroutine. And, this subroutine can be called any number of times.

Understanding the <SCRIPT> Tag

As you know, HTML uses tags to specify how the browser handles the document's content. In this section, I tell you everything you need to know about the soon-to-be-important <SCRIPT> tag.

Match 'em up

In HTML, tags usually surround the text they affect, which means that the tags must be paired up properly. For example, every <H1> tag requires a corresponding </H1> tag.

The <SCRIPT> tag is no exception. Every time you insert a <SCRIPT> tag, make sure that you add a matching </SCRIPT> tag. Failure to do so causes Internet Explorer to simply ignore everything after the <SCRIPT> tag -- and the script won't execute. The VBScript that's inserted between the <SCRIPT> and </SCRIPT> tag is referred to as a script block.

How many script blocks?

A single HTML document can include as many script blocks as needed. If you insert VBScript code that will be executed as the document is being loaded, you simply insert the scripts where they are needed in the document. Each script block has its own <SCRIPT> and </SCRIPT> tags.

If you're using VBScript subroutines or functions, placing them all within a single set of <SCRIPT></SCRIPT> tags is usually a good idea because it keeps them together in one place. But this placement isn't a requirement; you can arrange things any way you like.

Where to put scripts

As far as I know, no hard-and-fast rules govern where in the document scripts should be placed. Here are a few guidelines.

  • If you're using an immediate script that generates content, the script goes in its appropriate place within the <BODY> section -- the location in which you want the content to appear. However, the script can't refer to objects that are defined later in the document.
  • Subroutines and functions can go anywhere, but placing them in the <HEAD> section is often a good idea. By doing so, if the page loading stops before it finishes, you have a better chance that the scripts will have already loaded.

The LANGUAGE attribute for <SCRIPT>

Many HTML tags include attributes. Think of an attribute as supplying further instructions to the browser. The following HTML tag uses the WIDTH attribute to specify the width of a table:


The <SCRIPT> tag has only one attribute: LANGUAGE

For your purposes, the LANGUAGE attribute's value will always be "VBScript." Including this attribute is necessary because VBScript is not the only scripting language. (JavaScript is the only other language, for now.)

Note: Although you may be able to omit the LANGUAGE attribute in some cases, practice using it all the time. If this attribute is omitted, Internet Explorer assumes that the script is written in the most recently used scripting language it encountered.

What about older browsers?

You may be curious about what happens if someone accesses your Web page using an older browser -- one that has no concept of the <SCRIPT> tag. Most browsers simply ignore tags that they don't understand. However, the VBScript code in between the <SCRIPT> and </SCRIPT> tags is interpreted as plain text and displayed as is. Although this treatment probably doesn't ruin anyone's day, it does make your Web site look like it's broken (or at least seriously wounded).

To avoid an injured Web page, get into the habit of hiding your VBScript code inside of HTML comment tags. HTML comment tags are

<!- - The tag that begins the comment

- - > The tag that ends the comment

Here's an example of a comment in HTML:

<!--The order form begins here -->

Here's an example of using comment tags to hide VBScript from older browsers:



Alert "If you see this message, your browser supports VBScript!" >


Newer, script-aware browsers (including Netscape Navigator) are programmed to ignore comment tags that fall in between <SCRIPT> and <SCRIPT> tags.

To save space -- and because I know that everyone using these examples does have a VBScript-compatible browser -- most examples in this book do not enclose the VBScript code in between HTML comment tags. In general, any page you produce for public consumption should include comment tags. To add comment tags to scripts, insert the following HTML begin comment tag after every occurrence of a <SCRIPT> tag:


And, insert the following HTML end comment tag before every occurrence of the </SCRIPT> tag:


Writing VBScript Code

In this section, I provide some additional information about the mechanics of writing VBScript code. I cover the following topics:

  • Using comments in your code
  • Using upper- and lowercase
  • Using spaces and tabs to provide indentation
  • Splitting a VBScript statement into two or more lines

Using comments in VBScript code

In the previous section, I discuss HTML comment tags. In case you're wondering, VBScript has its own way of handling comments. You may want to include comments in your code to describe what the code does or to identify yourself as the author. Because VBScript isn't HTML, you use the comment indicator for the VBScript language -- which happens to be an apostrophe. Whenever VBScript encounters an apostrophe, everything else on that line is simply ignored. The only exception is when the apostrophe falls within a pair of quotes. Here's an example of a VBScript subroutine that uses three comments. The comment lines begin with an apostrophe:

Sub ShowMessage()
' This subroutine was written by Mike Jones
' Display the current date
Alert Date()
' Next, show the time of day
Alert Time()
End Sub

Upper- or lowercase?

The VBScript language is not case-sensitive. In other words, whether you use uppercase or lowercase in your scripts doesn't matter at all. The following VBScript statements are all equivalent as far as Internet Explorer is concerned.

Document.Write Document.LastModified


document.write document.lastmodified

DoCuMeNt.WrItE dOcUmEnT.lAsTmOdIfIeD

Although Internet Explorer doesn't care about upper- or lowercase, you may want to develop your own style. For example, some programmers prefer to use lowercase for everything. Other programmers like to use "proper" case -- they use uppercase for the first letter and lowercase for other letters.

Note: The exception to the "anything goes" rule for capitalization occurs with information within quote marks. Text within quotes is always interpreted literally, and Internet Explorer does not change such text. The following statements each display the exact message that's within quotes:


Alert "Hello User"

Alert "hello user"

Alert "HeLlO uSeR"

Indenting and spaces

When you write VBScript, you may find it helpful to indent your code to indicate the structure of the code. Here's an example of a simple VBScript subroutine that uses indentations:

Sub ShowMessage()

Alert Date()

Alert Time()

End Sub

Following is the same subroutine without indentation:

Sub ShowMessage()

Alert Date()

Alert Time()

End Sub

Internet Explorer is completely oblivious to the number of spaces (or tabs) that you use in your VBScript code. However, getting into the habit of using indentation to make your code more readable is a good idea.

Note: The importance of using indentation in your code is most apparent when you use For-Next loops, If-Then statements, and other such structures (see Chapter 9).

Splitting a statement into two or more lines

When you're writing HTML code, you can make the lines of text as long as you want. The same is true for writing VBScript code. Many programmers, however, prefer to break lengthy lines of code into two or more separate lines. To split a line of VBScript code, use the standard line continuation character sequence: a space followed by an underscore.

Here's an example of a VBScript statement that appears on one line.

Document.Write "This was modified on " & Document.LastModified

And here's the same statement, split into two lines.

Document.Write "This was modified on " _

& Document.LastModified

You need to decide when (if ever) to use line continuation character sequence. The only thing to keep in mind is that you cannot break a line inside of a quoted string. For example, the following is not a correct line break because the break occurs inside of the quoted text:

Document.Write "This was modified _

on " & Document.LastModified

Hey! That's Private!

Because your VBScript code is embedded directly in an HTML document, you may think that anyone who loads your page can look at your VBScript code. You're right. Anyone who sees your document can use the Internet Explorer View-->Source command to see every byte of your code.

Compatibility Issues

You need to understand that VBScript is not supported by all browsers. In fact, currently it's supported by exactly one browser: Internet Explorer 3.0. You need to keep this fact in mind -- especially because Netscape Navigator is (at least for now) the market share leader in the Web browser department.

A plug-in, which allows you to use VBScript with Netscape Navigator, is available. You can get this plug-in from the following Web site:

When to use VBScript

In general, using VBScript under the following conditions is safe:

  • You know that almost everyone who will load your Web document is using Internet Explorer 3.0 or later. This condition may be true in the case of a corporate Intranet or for sites that cater to a particular class of visitors.
  • The features for which you're using VBScript are not critical to the Web page. If you're using VBScript to add snazzy effects, those who don't have a compatible browser aren't missing out on anything critical.
  • You provide a screening page that lets the user determine whether to load the VBScript-enhanced version of your page or the boring generic version that works for all browsers.

In Chapter 15, I present a method that automatically determines whether the user's browser is VBScript-compatible.

When to avoid VBScript

If you don't know which browser your visitors will be using, you'll generally want to avoid using VBScript for critical aspects of your site. For example, you probably won't want to rely on VBScript to generate an order form for a product. Doing so eliminates a good chunk of potential customers (those whose browsers don't support VBScript).

More browsers will likely support VBScript in the not-so-distant future. But for the time being, you need to carefully evaluate the ramifications of using VBScript for critical components of your site.

VBScript versus JavaScript

You've probably heard of JavaScript -- and I've even referred to it several times already. JavaScript, like VBScript, is a scripting language that is used for programming Web pages. Both languages use code that is embedded directly within HTML documents.

So what's the difference? I've attempted to summarize these two languages in Table 4-1. As you see, both languages have their advantages and disadvantages (so what else is new?).

Table 4-1 VBScript versus JavaScript

VBScript JavaScript
Developer Microsoft Sun Microsystems
Easy to learn Yes Not really
Easy to read Yes Not really
Supported by MS Internet Explorer Yes Yes
Supported by Netscape Navigator No* Yes
In widespread use Not yet Yes
*It's quite likely that a future version of Navigator will support VBScript.

Both of these scripting languages are pretty much capable of doing the same sorts of things. But the real advantages of VBScript (at least to me) is that it is much easier to learn and to use. And if your primary objective is to produce slick Web pages with minimal fuss, ease of use can be a very important consideration.

To demonstrate how different these scripting languages are, I developed a simple example programmed in both JavaScript and VBScript. When you load the HTML document, you see two buttons -- one executes the VBScript code, and the other executes the JavaScript code. You might want to view the source document to see how the two languages differ. (I think you'll find that the VBScript code is much easier to understand.)

Clicking a button presents you with a dialog box asking for a number. Enter a number, and another dialog box displays the square root of the number. Figure 4-3 shows an example of how the result is displayed.

Note: This example also demonstrates that these two scripting languages can coexist quite peacefully in a single HTML document.

Read More Show Less

Customer Reviews

Be the first to write a review
( 0 )
Rating Distribution

5 Star


4 Star


3 Star


2 Star


1 Star


Your Rating:

Your Name: Create a Pen Name or

Barnes & Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation


  • - By submitting a review, you grant to Barnes & and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Terms of Use.
  • - Barnes & reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously

    If you find inappropriate content, please report it to Barnes & Noble
    Why is this product inappropriate?
    Comments (optional)