VBScript in a Nutshell

  • Authors:
  • Paul Lomax;Ron Petrusha

  • Affiliations:
  • -;-

  • Venue:
  • VBScript in a Nutshell
  • Year:
  • 2000

Quantified Score

Hi-index 0.00

Visualization

Abstract

From the Book:Visual Basic Scripting Edition, or VBScript, as it's commonly called, began its life amid a certain amount of fanfare as a client-side scripting language for web browsers. Its appeal was that it was a subset of Visual Basic for Applications (VBA), the most widely used programming language in the world, and hence promised to make Internet programming easy not only for the huge installed base of VB/VBA programmers, but also for new programmers as well. But for the most part, VBScript failed to deliver on its promise as a client-side scripting language. The problem wasn't the language or its capabilities: rather, VBScript suffered from the fact that it was the second language to arrive in the arena of client-side scripting, and was never able to supplant its rival, JavaScript. In fact, Netscape Navigator, the browser with the largest market share at the time, completely failed to support VBScript, leaving VBScript as a language that could be used exclusively for client-side scripting on corporate intranets (or for content providers on the public Internet who didn't care that their content was incompatible with most browsers). But while VBScript's success as a client-side scripting language has been marginal, it has become one of the three major scripting languages (along with JavaScript and Perl) in use today. With the release of Internet Information Server 2.0 (IIS) in 1997, VBScript rapidly became the primary scripting language used in developing Active Server Pages (ASP), Microsoft's server-side scripting technology for IIS. Also in 1997, Microsoft released the first version of Outlook, which was programmable and customizable only by using VBScript.Finally, in 1998, Microsoft released the first version of Windows Script Host (WSH), the long awaited "batch language" for Windows. Here again, VBScript rapidly emerged as the predominant choice for writing WSH scripts. Why ?'his Book? 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: It consistently offers a rather bare-bones approach to the language. There isn't a level of detail that allows one to move beyond the basics or to make the documentation useful in troubleshooting and diagnosing sources of error. The examples rarely, if ever, move beyond the self-evident and obvious. In some cases, it incorrectly documents a feature that turns out not to work in VBScript, but that is implemented in VBA. This leads one to suspect that the documentation was originally written for VBA and then was rather quickly adapted to VBScript. Since one of the strengths of VBScript is that it allows VBA programmers to leverage their existing skills in learning a new technology, it is peculiar that the documentation totally disregards differences between VBA and VBScript. 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...