You are previewing VBScript in a Nutshell, 2nd Edition.
O'Reilly logo
VBScript in a Nutshell, 2nd Edition

Book Description

Lightweight yet powerful, VBScript from Microsoft® is used in four main areas: server-side web applications using Active Server Pages (ASP), client-side web scripts using Internet Explorer, code behind Outlook forms, and automating repetitive tasks using Windows Script Host (WSH). VBScript in a Nutshell, Second Edition delivers current and complete documentation for programmers and system administrators who want to develop effective scripts. Completely updated for VBScript 5.6, WSH 5.6 and ASP 3.0, VBScript In a Nutshell, Second Edition includes updated introductory chapters that will help you keep current with the significant changes since the first edition was published. New chapters introduce the Windows Script Component for creating binary COM components, and the Script Encoder. The main part of the book is a comprehensive reference focusing on VBScript essentials with an alphabetical reference to all statements, keywords and objects, and a section of notes and solutions to real-world gotchas--various undocumented behaviors and aspects of the language--to help you avoid potential problems. Each entry in the reference section details the following:

  • The keyword's syntax, using standard code conventions

  • A list of arguments accepted by the function or procedure, if any exist

  • A discussion of how and where the keyword should be used within the scripting environment

  • A discussion of the differences between the operation of the keyword in Visual Basic or VBA and in VBScript

  • Regardless of your level of experience programming with VBScript, VBScript in a Nutshell, Second Edition is the book you'll want by your side--the most complete, up-to-date, and easy-to-use language reference available.

    Table of Contents

    1. VBScript in a Nutshell, 2nd Edition
    2. Foreword
    3. Preface
      1. Why This Book?
      2. Who Should Read This Book?
      3. How This Book Should Be Used
        1. If You're New to VBScript
        2. If You're a VBScript Programmer
        3. If You're a VB or VBA Developer New to VBScript
      4. How This Book Is Structured
        1. The Format of the Language Reference
      5. Conventions in This Book
      6. How To Contact Us
        1. Acknowledgments
    4. I. The Basics
      1. 1. Introduction
        1. 1.1. VBScript's History and Uses
        2. 1.2. What VBScript Is Used For: Gluing Together Objects
          1. 1.2.1. Properties
          2. 1.2.2. Methods
          3. 1.2.3. Events
        3. 1.3. Differences Between VBScript and VBA
      2. 2. Program Structure
        1. 2.1. Functions and Procedures
          1. 2.1.1. Defining Subroutines: The Sub . . . End Sub Construct
          2. 2.1.2. Calling a Subroutine
          3. 2.1.3. Defining Functions: The Function . . . End Function Construct
          4. 2.1.4. Passing Variables into a Subroutine
          5. 2.1.5. Exiting a Routine with the Exit Statement
        2. 2.2. Classes
          1. 2.2.1. The Class Construct
          2. 2.2.2. Class Variables
          3. 2.2.3. Class Properties
          4. 2.2.4. Class Methods
          5. 2.2.5. Class Events
        3. 2.3. Global Code
          1. 2.3.1. Active Server Pages
          2. 2.3.2. Windows Script Host
          3. 2.3.3. Client-Side Scripts for Internet Explorer
          4. 2.3.4. Outlook Forms
        4. 2.4. Reusable Code Libraries
          1. 2.4.1. Active Server Pages
          2. 2.4.2. Windows Script Host
          3. 2.4.3. Client-Side Scripts for Internet Explorer
      3. 3. Data Types and Variables
        1. 3.1. VBScript Data Types: The Many Faces of the Variant
          1. 3.1.1. Variant Data Types
          2. 3.1.2. Determining the Variant Type
            1. 3.1.2.1. VarType
            2. 3.1.2.2. TypeName
          3. 3.1.3. Converting from One Data Type to Another
        2. 3.2. Variables and Constants
          1. 3.2.1. What Is a Variable?
          2. 3.2.2. What Is a Constant?
          3. 3.2.3. Intrinsic Constants
          4. 3.2.4. Constants in Type Libraries
          5. 3.2.5. Declaring Variables and Constants
            1. 3.2.5.1. Option Explicit
          6. 3.2.6. Array Variables
            1. 3.2.6.1. Fixed arrays
            2. 3.2.6.2. Dynamic arrays
            3. 3.2.6.3. Determining array boundaries: UBound and LBound
            4. 3.2.6.4. Multidimensional arrays
            5. 3.2.6.5. Dynamic multidimensional arrays
            6. 3.2.6.6. Using UBound with multidimensional arrays
          7. 3.2.7. Scope and Visibility
            1. 3.2.7.1. Global scope
            2. 3.2.7.2. Local scope
            3. 3.2.7.3. Public visibility
            4. 3.2.7.4. Private
      4. 4. Error Handling and Debugging
        1. 4.1. Debugging
          1. 4.1.1. Syntax Errors
            1. 4.1.1.1. Syntax errors at compile time
            2. 4.1.1.2. Syntax errors at runtime
          2. 4.1.2. Logical Errors
            1. 4.1.2.1. Logical errors that affect program results
            2. 4.1.2.2. Logical errors that generate error messages
          3. 4.1.3. The Microsoft Script Debugger
            1. 4.1.3.1. Launching the Script Debugger
            2. 4.1.3.2. The Script Debugger interface
            3. 4.1.3.3. Tracing execution with the Script Debugger
            4. 4.1.3.4. Determining the value of a variable, expression, or function at runtime
            5. 4.1.3.5. Changing variable values at runtime
        2. 4.2. Error Handling
          1. 4.2.1. The On Error Resume Next Statement
          2. 4.2.2. The Err Object
            1. 4.2.2.1. Err object properties
            2. 4.2.2.2. Err object methods
        3. 4.3. Common Problem Areas and How to Avoid Them
      5. 5. VBScript with Active Server Pages
        1. 5.1. How ASP Works
          1. 5.1.1. The global.asa File
          2. 5.1.2. Including Server-Side Script in Web Pages
        2. 5.2. Active Server Pages Object Model
      6. 6. Programming Outlook Forms
        1. 6.1. Why Program Outlook Forms?
        2. 6.2. The Form-Based Development Environment
          1. 6.2.1. Interfaces and Objects
          2. 6.2.2. Outlook Form Design Mode
          3. 6.2.3. The VBScript Environment
        3. 6.3. Running Your Code
        4. 6.4. Program Flow
        5. 6.5. The Outlook Object Model
          1. 6.5.1. The Current Item
          2. 6.5.2. The Inspector Object
          3. 6.5.3. The Pages Collection
          4. 6.5.4. The FormDescription Object
          5. 6.5.5. The NameSpace Object
          6. 6.5.6. The MAPIFolder Object
          7. 6.5.7. Outlook Constants
        6. 6.6. Accessing Other Object Models
      7. 7. Windows Script Host 5.6
        1. 7.1. Why Use WSH?
        2. 7.2. Running WSH Scripts
        3. 7.3. Program Flow
          1. 7.3.1. Simple Script Files
          2. 7.3.2. Script Files with XML Code
        4. 7.4. The WSH Object Model
          1. 7.4.1. The WScript Object
          2. 7.4.2. The WshArguments Object
          3. 7.4.3. The WshController Object
          4. 7.4.4. The WshEnvironment Object
          5. 7.4.5. The WshNamed Object
          6. 7.4.6. The WshNetwork Object
          7. 7.4.7. The WshRemote Object
          8. 7.4.8. The WshRemoteError Object
          9. 7.4.9. The WshScriptExec Object
          10. 7.4.10. The WshShell Object
          11. 7.4.11. The WshShortcut Object
          12. 7.4.12. The WshSpecialFolders Object
          13. 7.4.13. The WshUnnamed Object
          14. 7.4.14. The WshUrlShortcut Object
        5. 7.5. WSH Language Elements
        6. 7.6. Accessing Other Object Models
      8. 8. VBScript with Internet Explorer
        1. 8.1. The <SCRIPT> Tag
          1. 8.1.1. <SCRIPT> Attributes
            1. 8.1.1.1. The LANGUAGE attribute
            2. 8.1.1.2. The SRC attribute
            3. 8.1.1.3. The FOR attribute
          2. 8.1.2. Where to Place the <SCRIPT> Tag
          3. 8.1.3. Using <!——> with <SCRIPT>
        2. 8.2. What Can You Do with Client-Side Scripting?
          1. 8.2.1. Interacting with the Client
          2. 8.2.2. Handling Events
          3. 8.2.3. Data Validation
        3. 8.3. Understanding the IE Object Model
          1. 8.3.1. The Window Object
          2. 8.3.2. The Document Object
          3. 8.3.3. The Elements Collection and HTML Intrinsic Controls
            1. 8.3.3.1. The textbox control
            2. 8.3.3.2. The checkbox control
            3. 8.3.3.3. The radio button control
            4. 8.3.3.4. The list box
            5. 8.3.3.5. Command button controls
          4. 8.3.4. The History Object
          5. 8.3.5. The Event Object
          6. 8.3.6. Using the Document Object Model
      9. 9. Windows Script Components
        1. 9.1. The Script Component Wizard
        2. 9.2. Writing Component Code
        3. 9.3. Using the Component
          1. 9.3.1. Registration
          2. 9.3.2. Instantiating the Component
        4. 9.4. WSC Programming Topics
          1. 9.4.1. Handling Events
          2. 9.4.2. Using an Interface Handler: ASP
          3. 9.4.3. Using Resources
          4. 9.4.4. Building an Object Model
    5. II. Reference
      1. 10. The Language Reference
        1. Abs Function
        2. Array Function
        3. Asc, AscB, AscW Functions
        4. Atn Function
        5. Call Statement
        6. CBool Function
        7. CByte Function
        8. CCur Function
        9. CDate Function
        10. CDbl Function
        11. Chr, ChrB, ChrW Functions
        12. CInt Function
        13. Class Statement
        14. CLng Function
        15. Const Statement
        16. Cos Function
        17. CreateObject Function
        18. CSng Function
        19. CStr Function
        20. Date Function
        21. DateAdd Function
        22. DateDiff Function
        23. DatePart Function
        24. DateSerial Function
        25. DateValue Function
        26. Day Function
        27. Dictionary Object
        28. Dictionary.Add Method
        29. Dictionary.CompareMode Property
        30. Dictionary.Count Property
        31. Dictionary.Exists Method
        32. Dictionary.Item Property
        33. Dictionary.Items Method
        34. Dictionary.Key Property
        35. Dictionary.Keys Method
        36. Dictionary.Remove Method
        37. Dictionary.RemoveAll Method
        38. Dim Statement
        39. Do . . . Loop Statement
        40. Drive Object
        41. Drives Collection Object
        42. End . . . Statement
        43. Erase Statement
        44. Err Object
        45. Err.Clear Method
        46. Err.Description Property
        47. Err.HelpContext Property
        48. Err.HelpFile Property
        49. Err.Number Property
        50. Err.Raise Method
        51. Err.Source Property
        52. Escape Function
        53. Eval Function
        54. Execute Statement
        55. ExecuteGlobal Statement
        56. Exit Statement
        57. Exp Function
        58. File Object
        59. File.Copy Method
        60. File.Delete Method
        61. File.Move Method
        62. File.OpenAsTextStream Method
        63. File System Object Model
        64. Files Collection Object
        65. FileSystemObject Object
        66. FileSystemObject.BuildPath Method
        67. FileSystemObject.CopyFile Method
        68. FileSystemObject.CopyFolder Method
        69. FileSystemObject.CreateFolder Method
        70. FileSystemObject.CreateTextFile Method
        71. FileSystemObject.DeleteFile Method
        72. FileSystemObject.DeleteFolder Method
        73. FileSystemObject.DriveExists Method
        74. FileSystemObject.Drives Property
        75. FileSystemObject.FileExists Method
        76. FileSystemObject.FolderExists Method
        77. FileSystemObject.GetAbsolutePathName Method
        78. FileSystemObject.GetBaseName Method
        79. FileSystemObject.GetDrive Method
        80. FileSystemObject.GetDriveName Method
        81. FileSystemObject.GetExtensionName Method
        82. FileSystemObject.GetFile Method
        83. FileSystemObject.GetFileName Method
        84. FileSystemObject.GetFileVersion Method
        85. FileSystemObject.GetFolder Method
        86. FileSystemObject.GetParentFolderName Method
        87. FileSystemObject.GetSpecialFolder Method
        88. FileSystemObject.GetStandardStream Method
        89. FileSystemObject.GetTempName Method
        90. FileSystemObject.MoveFile Method
        91. FileSystemObject.MoveFolder Method
        92. FileSystemObject.OpenTextFile Method
        93. Filter Function
        94. Fix Function
        95. Folder Object
        96. Folder.Copy Method
        97. Folder.CreateTextFile Method
        98. Folder.Delete Method
        99. Folder.Move Method
        100. Folders Collection Object
        101. Folders.Add Method
        102. For . . . Next Statement
        103. For Each . . . Next Statement
        104. FormatCurrency, FormatNumber, FormatPercent Functions
        105. FormatDateTime Function
        106. Function Statement
        107. GetLocale Function
        108. GetObject Function
        109. GetRef Function
        110. Hex Function
        111. Hour Function
        112. If . . . Then . . . Else Statement
        113. Initialize Event
        114. InputBox Function
        115. InStr, InStrB Functions
        116. InstrRev Function
        117. Int Function
        118. Is Operator
        119. IsArray Function
        120. IsDate Function
        121. IsEmpty Function
        122. IsNull Function
        123. IsNumeric Function
        124. IsObject Function
        125. Join Function
        126. LBound Function
        127. LCase Function
        128. Left, LeftB Functions
        129. Len, LenB Functions
        130. LoadPicture Function
        131. Log Function
        132. LTrim Function
        133. Match Object
        134. Matches Collection Object
        135. Me Keyword
        136. Mid, MidB Functions
        137. Minute Function
        138. Month Function
        139. MonthName Function
        140. MsgBox Function
        141. Now Function
        142. Oct Function
        143. On Error Statement
        144. Option Explicit Statement
        145. Private Statement
        146. Property Get Statement
        147. Property Let Statement
        148. Property Set Statement
        149. Public Statement
        150. Randomize Sub
        151. ReDim Statement
        152. RegExp Object
        153. RegExp.Execute Method
        154. RegExp.Global Property
        155. RegExp.IgnoreCase Property
        156. RegExp.Pattern Property
        157. RegExp.Replace Method
        158. RegExp.Test Method
        159. Rem Statement
        160. Replace Function
        161. RGB Function
        162. Right, RightB Functions
        163. Rnd Function
        164. Round Function
        165. RTrim Function
        166. ScriptEngine Function
        167. ScriptEngineBuildVersion Function
        168. ScriptEngineMajorVersion Function
        169. ScriptEngineMinorVersion Function
        170. Second Function
        171. Select Case Statement
        172. SetLocale Function
        173. Set Statement
        174. Sgn Function
        175. Sin Function
        176. Space Function
        177. Split Function
        178. Sqr Function
        179. StrComp Function
        180. String Function
        181. StrReverse Function
        182. Sub Statement
        183. Tan Function
        184. Terminate Event
        185. TextStream Object
        186. TextStream.Close Method
        187. TextStream.Read Method
        188. TextStream.ReadAll Method
        189. TextStream.ReadLine Method
        190. TextStream.Skip Method
        191. TextStream.SkipLine Method
        192. TextStream.Write Method
        193. TextStream.WriteBlankLines Method
        194. TextStream.WriteLine Method
        195. Time Function
        196. Timer Function
        197. TimeSerial Function
        198. TimeValue Function
        199. Trim Function
        200. TypeName Function
        201. UBound Function
        202. UCase Function
        203. Unescape function
        204. VarType Function
        205. Weekday Function
        206. WeekdayName Function
        207. While . . . Wend Statement
        208. With Statement
        209. Year Function
    6. III. Appendixes
      1. A. Language Elements by Category
        1. A.1. Array Handling
        2. A.2. Assignment
        3. A.3. Comment
        4. A.4. Constants
        5. A.5. Data Type Conversion
        6. A.6. Date and Time
        7. A.7. Dictionary Object
        8. A.8. Error Handling
        9. A.9. File System Objects
          1. A.9.1. Drive Object
          2. A.9.2. Drives Collection Object
          3. A.9.3. File Object
          4. A.9.4. Files Collection Object
          5. A.9.5. FileSystemObject Object
          6. A.9.6. Folder Object
          7. A.9.7. Folders Collection Object
          8. A.9.8. TextStreamObject
        10. A.10. Information Functions
        11. A.11. Mathematical and Numeric
        12. A.12. Miscellaneous
        13. A.13. Object Programming
        14. A.14. Program Structure and Flow
        15. A.15. String Manipulation
        16. A.16. User Interaction
        17. A.17. Variable Declaration
      2. B. VBScript Constants
        1. B.1. Color Constants
        2. B.2. Comparison Constants
        3. B.3. Date and Time Constants
        4. B.4. Date Format Constants
        5. B.5. Error Constant
        6. B.6. Logical and TriState Constants
        7. B.7. Message Box Constants
        8. B.8. String Constants
        9. B.9. Variable Type Constants
      3. C. Operators
        1. C.1. Arithmetic Operators
        2. C.2. String Operator
        3. C.3. Comparison Operators
          1. C.3.1. The Is Operator
        4. C.4. Logical and Bitwise Operators
        5. C.5. Operator Precedence
      4. D. Locale IDs
      5. E. The Script Encoder
        1. E.1. How Encoding and Decoding Works
        2. E.2. Script Encoder Syntax
        3. E.3. Encoding Examples
          1. E.3.1. Encoding .vbs Files
          2. E.3.2. Encoding .wsf Files
          3. E.3.3. Encoding ASP Files with Client-Side Script
    7. About the Authors
    8. Colophon
    9. Copyright