Cover image for VBScript in a Nutshell

Book description

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:

  • The syntax, using standard code conventions

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

  • A description of the data returned by a function

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

  • A section of notes and solutions to real-world gotchas, and various undocumented behaviors and aspects of the language that help the reader avoid potential problems

  • A section that focuses on the differences between the language element in VBA and in VBScript

  • A brief example to illustrate the use of the keyword

  • Basic language information on VBScript data types, constants, variables, and arrays

  • The difference between VBScript and VBA or JavaScript

  • The use of the MSIE, Active Server, Outlook, and Windows Script Host object models to interface a script with the application it's controlling

  • Tables listing VBScript functions and statements by category

  • The version-specific features of VBScript

Supplementing this focus on VBScript language essentials is a wealth of additional information about VBScript, including:

Regardless of the types of scripts you're using VBScript to create, VBScript in a Nutshell is the only book you'll need by your side--a complete and easy-to-use language reference.

Table of Contents

  1. VBScript in a Nutshell
    1. 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. Call for Additions and Amendments
    2. I. The Basics
      1. 1. Introduction
        1. VBScript’s History and Uses
        2. What VBScript Is Used For: Gluing Together Objects
          1. Properties
            1. Methods
            2. Events
        3. Differences Between VBScript and VBA
      2. 2. Program Structure
        1. Functions and Procedures
          1. Defining Subroutines: The Sub . . . End Sub Construct
          2. Calling a Subroutine
          3. Defining Functions: The Function . . . End Function Construct
          4. Passing Variables into a Subroutine
          5. Exiting a Routine with the Exit Statement
        2. Class Modules
          1. The Class Construct
          2. Class Variables
          3. Class Properties
          4. Class Methods
          5. Class Events
        3. The Script Level
          1. Active Server Pages
          2. Windows Script Host
          3. Client-Side Scripts for MSIE
          4. Outlook Forms
        4. Reusable Code Libraries
          1. Active Server Pages
          2. Windows Script Host
          3. Client-Side Scripts for MSIE
      3. 3. Data Types and Variables
        1. VBScript Data Types: The Many Faces of the Variant
          1. Variant Data Subtypes
          2. Determining the Variant Subtype
            1. VarType
            2. TypeName
          3. Converting from One Data Subtype to Another
        2. Variables and Constants
          1. What Is a Variable?
          2. What Is a Constant?
          3. Intrinsic Constants
          4. Constants in Type Libraries
          5. Declaring Variables and Constants
            1. Option Explicit
          6. Array Variables
            1. Fixed arrays
            2. Dynamic arrays
            3. Determining array boundaries: UBound and LBound
            4. Multidimensional arrays
            5. Dynamic Multidimensional Arrays
            6. Using UBound with multidimensional arrays
          7. Scope
            1. Script-level scope
            2. Procedure-level scope
            3. Public Scope
            4. Private
      4. 4. Error Handling and Debugging
        1. Debugging
          1. Syntax Errors
            1. Syntax errors at compile time
            2. Syntax errors at runtime
          2. Logical Errors
            1. Logical errors that affect program results
            2. Logical errors that generate error messages
          3. The Microsoft Script Debugger
            1. Launching the Script Debugger
            2. The Script Debugger interface
            3. Tracing execution with the Script Debugger
            4. Determining the value of a variable, expression, or function at runtime
            5. Changing variable values at runtime
        2. Error Handling
          1. The On Error Resume Next Statement
          2. The Err Object
            1. Err object properties
            2. Err object methods
        3. Common Problems Areas, and How to Avoid Them
      5. 5. VBScript with Active Server Pages
        1. How ASP Works
          1. The global.asa File
          2. Including Server-Side Script in Web Pages
        2. Active Server Pages Object Model
          1. Application
            1. ObjectContext
            2. Request
            3. Response
            4. Server
            5. Session
      6. 6. Programming Outlook Forms
        1. Why Program Outlook Forms?
        2. The Form-Based Development Environment
          1. Interfaces and Objects
          2. Outlook Form Design Mode
          3. The VBScript Environment
        3. Running Your Code
        4. Program Flow
        5. The Outlook Object Model
          1. The Current Item
          2. The Inspector Object
          3. The Pages Collection
          4. The FormDescription Object
          5. The NameSpace Object
          6. The MAPIFolder Object
          7. Outlook Constants
        6. Accessing Other Object Models
      7. 7. Windows Script Host
        1. Why Use WSH?
        2. Running WSH Scripts
        3. Program Flow
          1. Simple Script Files
          2. Script Files with XML Code
        4. The WSH Object Model
          1. The WScript Object
          2. The WshArguments Object
          3. The WshEnvironment Object
          4. The WshNetwork Object
          5. The WshShell Object
          6. The WshShortcut Object
          7. The WshSpecialFolders Object
          8. The WshUrlShortcut Object
        5. WSH Language Elements
        6. Accessing Other Object Models
      8. 8. VBScript with Internet Explorer
        1. The <SCRIPT> Tag
          1. <SCRIPT> Attributes
            1. The LANGUAGE attribute
            2. The SRC attribute
            3. The FOR attribute
          2. Where to Place the <SCRIPT> Tag
          3. Using <!——> with <SCRIPT>
        2. What Can You Do with Client-Side Scripting?
          1. Interacting with the Client
          2. Handling Events
          3. Data Validation
        3. Understanding the IE Object Model
          1. The Window Object
          2. The Document Object
          3. The Elements Collection and HTML Intrinsic Controls
            1. The textbox control
            2. The checkbox control
            3. The radio button control
            4. The list box
            5. Command button controls
          4. The History Object
          5. The Event Object
          6. Using the Document Object Model
    3. II. Reference
      1. 9. 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. Exit Statement
        56. Exp Function
        57. File Object
        58. File.Copy Method
        59. File.Delete Method
        60. File.Move Method
        61. File.OpenAsTextStream Method
        62. File System Object Model
        63. Files Collection Object
        64. FileSystemObject Object
        65. FileSystemObject.BuildPath Method
        66. FileSystemObject.CopyFile Method
        67. FileSystemObject.CopyFolder Method
        68. FileSystemObject.CreateFolder Method
        69. FileSystemObject.CreateTextFile Method
        70. FileSystemObject.DeleteFile Method
        71. FileSystemObject.DeleteFolder Method
        72. FileSystemObject.DriveExists Method
        73. FileSystemObject.Drives Property
        74. FileSystemObject.FileExists Method
        75. FileSystemObject.FolderExists Method
        76. FileSystemObject.GetAbsolutePathName Method
        77. FileSystemObject.GetBaseName Method
        78. FileSystemObject.GetDrive Method
        79. FileSystemObject.GetDriveName Method
        80. FileSystemObject.GetExtensionName Method
        81. FileSystemObject.GetFile Method
        82. FileSystemObject.GetFileName Method
        83. FileSystemObject.GetFileVersion Method
        84. FileSystemObject.GetFolder Method
        85. FileSystemObject.GetParentFolderName Method
        86. FileSystemObject.GetSpecialFolder Method
        87. FileSystemObject.GetStandardStream Method
        88. FileSystemObject.GetTempName Method
        89. FileSystemObject.MoveFile Method
        90. FileSystemObject.MoveFolder Method
        91. FileSystemObject.OpenTextFile Method
        92. Filter Function
        93. Fix Function
        94. Folder Object
        95. Folder.Copy Method
        96. Folder.CreateTextFile Method
        97. Folder.Delete Method
        98. Folder.Move Method
        99. Folders Collection Object
        100. Folders.Add Method
        101. For . . . Next Statement
        102. For Each . . . Next Statement
        103. FormatCurrency, FormatNumber, FormatPercent Functions
        104. FormatDateTime Function
        105. Function Statement
        106. GetObject Function
        107. GetRef Function
        108. Hex Function
        109. Hour Function
        110. If . . . Then . . . Else Statement
        111. Initialize Event
        112. InputBox Function
        113. InStr, InStrB Functions
        114. InstrRev Function
        115. Int Function
        116. Is Operator
        117. IsArray Function
        118. IsDate Function
        119. IsEmpty Function
        120. IsNull Function
        121. IsNumeric Function
        122. IsObject Function
        123. Join Function
        124. LBound Function
        125. LCase Function
        126. Left, LeftB Functions
        127. Len, LenB Functions
        128. LoadPicture Function
        129. Log Function
        130. LTrim Function
        131. Match Object
        132. Matches Collection Object
        133. Me Operator
        134. Mid, MidB Functions
        135. Minute Function
        136. Month Function
        137. MonthName Function
        138. MsgBox Function
        139. Now Function
        140. Oct Function
        141. On Error Statement
        142. Option Explicit Statement
        143. Private Statement
        144. Property Get Statement
        145. Property Let Statement
        146. Property Set Statement
        147. Public Statement
        148. Randomize Statement
        149. ReDim Statement
        150. RegExp Object
        151. RegExp.Execute Method
        152. RegExp.Global Property
        153. RegExp.IgnoreCase Property
        154. RegExp.Pattern Property
        155. RegExp.Replace Method
        156. RegExp.Test Method
        157. Rem Statement
        158. Replace Function
        159. RGB Function
        160. Right, RightB Functions
        161. Rnd Function
        162. Round Function
        163. RTrim Function
        164. ScriptEngine Function
        165. ScriptEngineBuildVersion Function
        166. ScriptEngineMajorVersion Function
        167. ScriptEngineMinorVersion Function
        168. Second Function
        169. Select Case Statement
        170. Set Statement
        171. Sgn Function
        172. Sin Function
        173. Space Function
        174. Split Function
        175. Sqr Function
        176. StrComp Function
        177. String Function
        178. StrReverse Function
        179. Sub Statement
        180. Tan Function
        181. Terminate Event
        182. TextStream Object
        183. TextStream.Close Method
        184. TextStream.Read Method
        185. TextStream.ReadAll Method
        186. TextStream.ReadLine Method
        187. TextStream.Skip Method
        188. TextStream.SkipLine Method
        189. TextStream.Write Method
        190. TextStream.WriteBlankLines Method
        191. TextStream.WriteLine Method
        192. Time Function
        193. Timer Function
        194. TimeSerial Function
        195. TimeValue Function
        196. Trim Function
        197. TypeName Function
        198. UBound Function
        199. UCase Function
        200. Unescape function
        201. VarType Function
        202. Weekday Function
        203. WeekdayName Function
        204. While . . . Wend Statement
        205. With Statement
        206. Year Function
    4. III. Appendixes
      1. A. Language Elements by Category
        1. Array Handling
        2. Assignment
        3. Comment
        4. Constants
        5. Data Subtype Conversion
        6. Date and Time
        7. Dictionary Object
        8. Error Handling
        9. File System Objects
          1. Drive Object
          2. Drives Collection Object
          3. File Object
          4. Files Collection Object
          5. FileSystemObject Object
          6. Folder Object
          7. Folders Collection Object
          8. TextStreamObject
        10. Information Functions
        11. Mathematical and Numeric
        12. Miscellaneous
        13. Object Programming
        14. Program Structure and Flow
        15. String Manipulation
        16. User Interaction
        17. Variable Declaration
      2. B. VBScript Constants
        1. Color Constants
        2. Comparison Constants
        3. Date and Time Constants
        4. Date Format Constants
        5. Error Constant
        6. Logical and TriState Constants
        7. Message Box Constants
        8. String Constants
        9. Variable Type Constants
      3. C. Operators
        1. Arithmetic Operators
        2. String Operator
        3. Comparison Operators
          1. The Is operator
        4. Logical and Bitwise Operators
        5. Operator Precedence
    5. Index
    6. Colophon