- Shopping Bag ( 0 items )
Microsoft's Visual Basic Scripting Edition (VBScript), a subset of Visual Basic for Applications, is a powerful language for Internet application development, where it can serve as a scripting language for server-side Internet applications (i.e., Active Server Pages), and client-side web pages. It can also be used for system scripting (i.e., Windows Script Host scripts) and programming Outlook forms.The greater part of this book is an alphabetical VBScript language reference to all VBScript statements, keywords ...
Ships from: Springfield, VA
Usually ships in 1-2 business days
Microsoft's Visual Basic Scripting Edition (VBScript), a subset of Visual Basic for Applications, is a powerful language for Internet application development, where it can serve as a scripting language for server-side Internet applications (i.e., Active Server Pages), and client-side web pages. It can also be used for system scripting (i.e., Windows Script Host scripts) and programming Outlook forms.The greater part of this book is an alphabetical VBScript language reference to all VBScript statements, keywords and objects, emphasizing the following details:
A reference for intermediate- to advanced-level programmers documents the programming language's server-side applications, defines the differences between VBScript and Visual Basic, and describes necessary language components.
VBScript is, for the most part, a subset of the Visual Basic for Applications programming language. It was developed so that the millions of Visual Basic developers could leverage their knowledge of VB/VBA Internet scripting. One of the strengths of VBScript is that it uses the same familiar and easy syntax that has made VBA so popular as a programming language, making it very easy to learn for those who have some Visual Basic background. In addition, VBScript is fairly easy to learn for those without any programming experience.
Version 1.0 of VBScript was initially introduced in Microsoft Internet Explorer (MSIE) 3.0, which was released in 1996. Its intended use at that point was to allow web page developers to enhance their pages through client-side scripting. In contrast to plain HTML, which supported the creation of only static web pages, the combination of HTML and client-side script allows the creation of web pages that are both interactive and responsive to the user. For instance, a script could allow the web page to display extended information about hyperlinks as the user's mouse passes over them, or it could be used to validate data entered by the user without submitting it to the server. A script could even be used to generate a web page on the fly, without using any "hard-coded" HTML. The only limitation to VBScript as a language for client-side scripting was that VBScript could be used only inside of Internet Explorer, the only browser to support it, and thus was suitable only for use on corporate intranets that had standardized on MSIE. Using VBScript for clientside scripting on MSIE is discussed in Chapter 8, VBScript witb Internet Explorer.
Version 2.0 of VBScript was introduced in Internet Information Server (IIS) 3.0 in 1997. The most notable additions to the language were "web-friendly" language elements (such as lightweight Format... functions and the Filter, InStrRev, Reverse, and join functions) that in most cases were incorporated into the VBA language only with the release of VBA 6.0. In addition, VBScript 2.0 added support for a number of intrinsic constants to make code more readable and also implemented the Const statement to allow of user-defined constants. Finally, the Create0bject and GetObject functions were added to instantiate external COM objects; these functions, which are inoperative in a client-side scripting environment, are essential for supporting components that are capable of extending a scripted server-side application.
This new version of VBScript was released with IIS to support server-side scripting using ASP. ASP is itself the object model exposed by IIS that allows your script to access information about the client's request and to write to the server's output stream. An ASP application consists of conventional web pages (that is, HTML and possibly client-side script written in any language) along with script that executes on the server. The output of an ASP script most commonly is HTML, which is simply inserted into the output stream returned by the server in response to a client request. This makes ASP important for several reasons. First, it can be used to produce output that is customized for the browser on which it's displayed. Secondly, it provides a very strong web application environment, and particularly one that takes advantage of back-end processing. Along with ASP, Microsoft introduced ActiveX Data Objects (ADO) as its primary data access technology. Developing ASP applications with VBScript is discussed in Chapter 5, VBScript with Active Server Pages.
Although IIS itself is language-independent and supports a number of available scripting languages, it is precisely in this area-in scripting for ASP-that VBScript quickly found its major area of application.
Version 3.0 of VBScript, which was released in 1998, had no new language features. Nevertheless, it was significant for marking the spread of VBScript beyond a scripted web environment. Besides IIS Version 4.0 and MSIE Version 4.0, VBScript was now incorporated into Outlook 98 (an interim release of Outlook that was developed out of sync from the other applications in Microsoft Office), and Windows Script Host 1.0.
Microsoft Outlook was originally released in Office 97 as Microsoft's entry into the personal information manager/workgroup messaging market. Outlook featured a number of forms to handle standard MAPI message types (such as messages, contacts, tasks, notes, and appointments) out of the box. However, VBScript made it possible to design new forms and customize their behavior. Although Outlook's latest release, Outlook 2000, includes support for VBA, VBScript remains the programming language for Outlook 2000 forms. Developing Outlook forms with VBScript is covered in Chapter 6, Programming Outlook Forms.
Version 4.0 of VBScript was also released as part of Visual Studio 6.0 in 1998. As in version 3.0, no new language features were present. What was different was the Microsoft Scripting Runtime Library (scrrun.dll ), which now included a File System object model as well as the Dictionary object introduced with VBScript 2.0. The addition of the object model made the library an essential component in any scripted environment.
Version 5.0, shipped with MSIE 5.0 and IIS 5.0 (which shipped with Windows 2000), added a number of new language enhancements, including support for scripted classes using the Class ...End Class construct, support for regular expression searches through the RegExp object, and the ability to dynamically build expressions to be evaluated using the Eval function or executed using the Execute method.
As you can see, even though VBScript's advent as a client-side scripting language was largely unsuccessful, Microsoft remained committed to VBScript as a "lightweight" form of VBA and continued to move the language forward. As a result, it came to be used in a number of environments other than client-side scripts. and in fact has become one of the major scripting languages in use today.
What VBScript Is Used For.' Gluing Together Objects
We've outlined the four major areas in which VBScript is used, but if we were to look at how scripts are written in each of these environments, we'd quickly note far more differences than similarities. (Because of this, we've devoted a separate chapter to each area in which VBScript is commonly used.) Yet this is misleading. If we take a more high-level view, we can see that the role of VBScript and the role of the environment in which its scripts are run are broadly similar, regardless of the environment's unique features.
Typically, scripting languages are described as "glue" languages. That is, they are used to glue things together. That means that the glue itself does relatively little-it simply binds the rest of the script together. The "things" that the scripting language binds together are components or objects-that is, the objects exposed by the environment for which the script is being written (like ASP, MSIE, Outlook, or WSH), as well as objects that are exposed by external applications, environments, or components (such as ActiveX Data Objects, Collaboration Data Objects, Microsoft Word, Microsoft Excel, or custom components created in Visual Basic). A map of a single high-level object (such as the Microsoft Word application, for instance, which is represented by the Application object) along with its child objects is known as an object model.
One type of object model that's particularly suitable for scripting is shown in Figure 1-1. In this particular case, the figure shows the ASP object model. Two features are particularly noteworthy: its flatness and its lack of interdependence. (Contrast it, for example, with the Microsoft Word object model, a portion of which is shown in Figure 1-2.) In particular, a flatter object model and/or one whose objects have a fair degree of independence a number of advantages:
Ease of navigation
Since the object model is flat, you don't have to be concerned with navigating upward and downward through the object hierarchy. This makes coding easier, reduces the time spent debugging, and improves performance.
Ease of instantiating objects
Since objects are independent of one another, you can easily create them or retrieve a reference to them, instead of having to figure out to which portion of the object model you must navigate in order to instantiate that object or which property or method you must call that returns that object...
Individual objects within an object model expose properties, methods, and events. We'll discuss each of these in turn...
Why This Book?;
Who Should Read This Book?;
How This Book Should Be Used;
How This Book Is Structured;
Conventions in This Book;
How To Contact Us;
Chapter 1: Introduction;
1.1 VBScript’s History and Uses;
1.2 What VBScript Is Used For: Gluing Together Objects;
1.3 Differences Between VBScript and VBA;
Chapter 2: Program Structure;
2.1 Functions and Procedures;
2.2 Class Modules;
2.3 The Script Level;
2.4 Reusable Code Libraries;
Chapter 3: Data Types and Variables;
3.1 VBScript Data Types: The Many Faces of the Variant;
3.2 Variables and Constants;
Chapter 4: Error Handling and Debugging;
4.2 Error Handling;
4.3 Common Problems Areas, and How to Avoid Them;
Chapter 5: VBScript with Active Server Pages;
5.1 How ASP Works;
5.2 Active Server Pages Object Model;
Chapter 6: Programming Outlook Forms;
6.1 Why Program Outlook Forms?;
6.2 The Form-Based Development Environment;
6.3 Running Your Code;
6.4 Program Flow;
6.5 The Outlook Object Model;
6.6 Accessing Other Object Models;
Chapter 7: Windows Script Host;
7.1 Why Use WSH?;
7.2 Running WSH Scripts;
7.3 Program Flow;
7.4 The WSH Object Model;
7.5 WSH Language Elements;
7.6 Accessing Other Object Models;
Chapter 8: VBScript with Internet Explorer;
8.1 The Tag;
8.2 What Can You Do with Client-Side Scripting?;
8.3 Understanding the IE Object Model;
Chapter 9: The Language Reference;
Language Elements by Category;
Data Subtype Conversion;
Date and Time;
File System Objects;
Mathematical and Numeric;
Program Structure and Flow;
Date and Time Constants;
Date Format Constants;
Logical and TriState Constants;
Message Box Constants;
Variable Type Constants;
Logical and Bitwise Operators;
The major source of documentation for VBScript is the Visual Basic Scripting HTML Help file, the official documentation that is included with VBScript itself. While VBScript's online help is an indispensable resource that most VBScript programmers turn to first, it has a number of limitations:
In other words, the documentation included with VBScript just doesn't have the depth of information that you need when you need it. Most of us can get by dayto-day without even opening the help section. But when you need to open the help section, it's probably because you've either hit an unexpected problem or need to know what the consequences of coding a particular procedure in a particular way will be. However, the help sections tend only to show you how a function should be included in your code. This is understandable; after all, the help sections for any language by their very nature must be created before that language goes into general use, but it is only general everyday use in real-life situations that highlight how the language can best be used and its problems and pitfalls. Therefore, online help confines itself to the main facts: what the syntax is and, in a general way, how you should implement the particular function or statement.
This book takes up where the help section leaves off. Contained within these pages are the experiences of professional VB and VBScript developers who have used the languages all day, every day, over many years, to create complex applications. It is these experiences from which you can benefit. Whether you have come to VBScript recently or have been using VBScript since its introduction, there are always new tricks to learn, And it's always important to find out about the gotchas that'll getcha!
Who Should Read This Book?
This book is aimed at experienced VBScript developers or experienced developers coming to VBScript for the first time from another programming language or scripting language (including, of course, VB/VBA programmers).
This book is a reference work and not a tutorial-for example, we won't explain the concept of a For ...Next loop; as an experienced developer, you already know this, so you don't want someone like us insulting your intelligence. But we will explain in detail how a For. . .Next loop works in VB, how it works in practice, what the alternatives to it are, how it can be used to the best advantage, and what pitfalls it has and how to get around them.
Although this book is not intended as a tutorial, we have provided in Part I, The Basics, a concise introduction to the language that focuses not only on the general structure of the VBScript language, but on also its application in the four major environments in which it is used. If you're learning VBScript as a second language, the introduction combined with the reference is probably all that you'll need to get started.
How This Book Should Be Used
VBScript in a Nutshell focuses on the needs of three different audiences: programmers and script developers who are new to VBScript, VBScript programmers, and VB/VBA programmers who are new to VBScript.
If you're new to VBScript
This book is based upon the assumption that if you're new to VBScript, you know one or more other programming languages. The first half of the book leads you through the important areas of VBScript programming, which, while very different from most other languages, is straightforward and easily mastered. We suggest therefore that you read these chapters in order while referring to the Language Reference when necessary.
If you're a VBScript programmer
As an experienced VBScript programmer, you will be able to dip into the book to get the lowdown on the language element that interests you. Appendix A, Language Elements by Category, lists all the functions, statements and object models by category to help you find the relevant section in the Language Reference more easily.
If you're a VB or VBA developer new to VBScript
If you know VBA, you know VBScript, since the latter is a subset of the former. On the whole, you'll find that VBScript is a much "cleaner" language than VBA- many of the archaic elements of VBA (elements that survived as Basic and QBasic evolved into VBA and, as statement-based programming evolved into function-based programming and then object-based programming) have been removed from the language. But you'll also find some incompatibilities, as particular language features that you're accustomed to in VBA work differently in VBScript. We've tried to document those differences in this book.
How This Book Is Structured
This book is divided into three parts. The first part of the book, The Basics, 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 clientside 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, Introduction 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, Program Structure
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, Data Types and Variables
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, Error Handling and Debugging
On the assumption that we all strive to create robust applications, this chapter covers including error handling in your VBScript application and discusses the process of debugging in order to identify and remove program bugs.
Chapter 5, VBScript with Active Server Pages
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, Programming Outlook Forms
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 fortes-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, Windows Script Host
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 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 with Internet Explorer
VBScript was first introduced as a scripting language for Internet Explorer and 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, The Reference, consists of one large chapter, Chapter 9, The Language Reference, which 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 follwoing section for a detailed explanation of how to use the the Language Reference.
The third and final section consists of the following appendixes:
Appendix A, Language Elements by Category
Lists all VBScript functions, statements and major keywords by category.
Appendix B, VBScript Constants
Lists the constants built into the VBScript language and available at all times.
Appendix C, Operators
Lists the operators supported by VBScript, along with a slightly more detailed treatment of Boolean and bitwise operators...
Posted July 3, 2002