O'Reilly logo

VBScript in a Nutshell by Ron Petrusha, Paul Lomax, Matt Childs

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How This Book Is Structured

This book is divided into three parts. The first part of the book, Part I, is an introduction to the main features and concepts of VBScript programming, as well as an examination of how VBScript is used in its four major scripted environments: Active Server Pages, Windows Script Host, Outlook forms programming, and client-side scripting for Microsoft Internet Explorer (MSIE).

Even seasoned VB professionals should find items of interest here. If you’re new to VB, this part of the book is essential reading. This part is divided into the following chapters:

Chapter 1

In this chapter, you’ll find information on the VBScript language and how it fits in to the family of VB products. We’ll also discuss the notion that a scripting language is a kind of “glue” meant to hold together and control various objects. Finally, there’s also a short discussion of the history of VBA.

Chapter 2

This chapter details how to create the basic program structures in VBScript; how to implement classes, procedures, functions, and properties, and how program follow proceeds in a VBScript program.

Chapter 3

VBScript actually only has a single data type, the variant. This chapter looks at the variant and all its data subtypes and shows how to use them.

Chapter 4

On the assumption that we all strive to create robust applications, this chapter covers error handling in your VBScript application and discusses the process of debugging in order to identify and remove program bugs.

Chapter 5

This chapter shows how to incorporate VBScript code into an Active Sever Page and discusses the IIS object model that you access when creating an ASP application.

Chapter 6

Outlook 97 and 98 used VBScript as their only programming language and Outlook forms as their only programmable feature. Outlook 2000 includes two programming languages: VBA for application-level development and VBScript for forms-based development. In this chapter, we focus on the latter topic by examining the VBScript development environment, discussing how to structure and run Outlook code, and listing some of the basic objects in the Outlook object model.

Chapter 7

Programmers, administrators, and power users have long clamored for a “batch language” that would offer the power of the old DOS batch language in a graphical environment. Microsoft’s answer is Windows Script Host (WSH) and a scripting language of your choice. In this chapter, we look at VBScript as the “Windows batch language” by examining program flow and how to launch a WSH script, discussing the WSH object model, and focusing on the XML language elements that you can use to better structure your scripts.

Chapter 8

VBScript was first introduced as a scripting language for Internet Explorer, and this remains an important, although secondary, area of application for VBScript. In this chapter, we provide a quick overview of how to add script to HTML pages and focus on some of the functionality available through the MSIE object model.

The second part of the book, Part II, consists of one large chapter. Chapter 9 thoroughly details all the functions, statements, and object models that make up the VBScript language. The emphasis here is on the language elements found in VBScript 5 and 5.5 (which is currently in public beta). See the following section for a detailed explanation of how to use the Language Reference.

The third and final section, Part III, consists of the following appendixes:

Appendix A

Lists all VBScript functions, statements, and major keywords by category.

Appendix B

Lists the constants built into the VBScript language and available at all times.

Appendix C

Lists the operators supported by VBScript, along with a slightly more detailed treatment of Boolean and bitwise operators.

The Format of the Language Reference

The following template has been used for all functions and statements that appear in Chapter 9:

Syntax

This section uses standard conventions (detailed in the following section) to give a synopsis of the syntax used for the language item.

Description (of parameters and replaceable items)

Where applicable, this section details whether the item is optional, the data type of the item, and a brief description of the item.

Return Value

Where applicable, this section provides a very brief description of the value or data type returned by the function or property.

Description

This section provides a short description of what the language element does and when and why it should be used.

Rules at a Glance

This section describes the main points of how to use the function, presented in the form of a bulleted list to enable you to quickly scan through the list of rules. In the vast majority of cases, this section goes well beyond the basic details found in the VB documentation.

Example

It’s not uncommon for documentation to excel at providing bad examples. How often do we encounter code fragments like the following:

' Illustrate conversion from Integer to Long!
Dim iVar1 As Integer 
Dim lVar2 as Long
iVar1 = 3
lVar2 = CLng(iVar1)
Response.Write "The value of lVar2 is: " & lVar2

So you won’t find the gratuitous use of examples in this book. I see little point in including a one- or two-line code snippet that basically reiterates the syntax section. Therefore, we’ve tried to include examples only where they enhance the understanding of the use of a language element or demonstrate a poorly documented feature of a language element.

VBA/VBScript Differences

If you’re programming in the Professional or Enterprise Editions of Visual Basic or in one of the hosted environments (like Microsoft Word or AutoCAD) using Visual Basic for Applications, this section shows you how a particular VBScript language element differs from its VB/VBA counterpart. If no differences are noted, the element functions identically in both environments. This helps you get up to speed quickly with unfamiliar language elements quickly, but also helps you to get VBA code running under VBScript or VBScript code running under VBA.

Programming Tips and Gotchas

This is the most valuable section of the Language Reference, gained from years of experience using the VBA language in many different circumstances. The information included in here will save you countless hours of head-scratching and experimentation. This is the stuff Microsoft doesn’t tell you!

See Also

A simple cross-reference list of related or complimentary functions.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required