Vbscript Programmer's Reference
Total Page:16
File Type:pdf, Size:1020Kb
Table of Contents VBScript Programmer's Reference...................................................................................................................1 Introduction.........................................................................................................................................................6 Who is this Book For?............................................................................................................................6 How to Use this Book.............................................................................................................................6 What is VBScript?..................................................................................................................................7 What Can You Do With VBScript?......................................................................................................11 What Tools Do You Need to Use VBScript?.......................................................................................14 What's New in VBScript 5?..................................................................................................................15 Code Conventions.................................................................................................................................17 Tell Us What You Think.......................................................................................................................17 Customer Support.................................................................................................................................18 Chapter 1: A (Very) Short Introduction to Programming..........................................................................19 Overview...............................................................................................................................................19 Variables and Data Types.....................................................................................................................19 Control of Flow.....................................................................................................................................23 Operators...............................................................................................................................................31 Organizing and Reusing Code..............................................................................................................32 Top−Down vs. Event Driven................................................................................................................35 Some Guidelines to Keep in Mind........................................................................................................37 Suggestions for Further Reading..........................................................................................................39 Chapter 2: Variables and Data Types............................................................................................................40 The Visual Basic Data Types................................................................................................................40 The Variant: VBScript's Only Data Type.............................................................................................42 Variables in VBScript...........................................................................................................................60 Literals and Named Constants..............................................................................................................65 Complex Data Types.............................................................................................................................69 Chapter 3: Control of Flow.............................................................................................................................77 Branching Constructs............................................................................................................................77 Loop Constructs....................................................................................................................................81 Chapter 4: Error Handling, Prevention and Debugging.............................................................................93 Overview...............................................................................................................................................93 Introduction...........................................................................................................................................93 Seeing the Error of your Ways..............................................................................................................94 Different Types of Errors......................................................................................................................98 What Can We Do About Errors?........................................................................................................105 Debugging...........................................................................................................................................120 Common Errors and How To Avoid Them........................................................................................127 Summary.............................................................................................................................................128 Chapter 5: Using COM Components and Objects.....................................................................................129 Overview.............................................................................................................................................129 Introduction to COM components and Objects..................................................................................129 Object and Object Interfaces...............................................................................................................131 What COM Components and Objects are Available?........................................................................137 Objects and the Variant data type.......................................................................................................138 i Table of Contents Chapter 5: Using COM Components and Objects Properties and Methods.......................................................................................................................139 Object Scope, Lifetime and References..............................................................................................141 Using the With Statement with Objects..............................................................................................145 Create your own COM Objects...........................................................................................................146 Summary.............................................................................................................................................146 Chapter 6: Using COM Components with MTS.........................................................................................147 Overview.............................................................................................................................................147 A Quick Introduction to MTS.............................................................................................................147 Advantages of using MTS..................................................................................................................149 Next Step: COM+...............................................................................................................................158 Summary.............................................................................................................................................160 Chapter 7: The Built−In and Scripting Runtime Objects..........................................................................162 Overview.............................................................................................................................................162 Runtime vs. Built−In − What's the Difference?..................................................................................162 Built−In Objects..................................................................................................................................162 Regular Expressions............................................................................................................................163 Scripting Runtime Objects..................................................................................................................173 Summary.............................................................................................................................................182 Chapter 8: Classes in VBScript (Writing Your Own COM Objects).......................................................183 Classes vs. Objects vs. Components...................................................................................................183 Chapter 9: Windows Script Components....................................................................................................204 What Are Windows Script Components?...........................................................................................204 What Tools Do You Need?.................................................................................................................204