VBScript Constants
What Is a Constant?
A constant is a meaningful name that takes the place of a number or string and never changes. VBScript currently has no constants defined by the language. In VBScript, constants are implemented as literal values assigned to variable names.
Creating Constants
You create constants in VBScript the same way you declare variables, using the Dim statement. Using the Dim statement, you can create string or numeric constants with meaningful names. You can then assign them literal values and use them in your script. For example:
Note that the string literal is enclosed in quotation marks ("). Quotation marks are the best, most obvious way to differentiate string values from numeric values. Date/Time literals can be represented by enclosing them in number signs (#). For example:Dim MyString MyString = "This is my string." Dim MyAge MyAge = 49
Since there is no functional difference between constants created in this way and regular variables, you may want to adopt a naming scheme to differentiate constants from variables. This will prevent you from trying to reassign their values while your script is running. For example, you might want to use a "vb" prefix on your constant names, or you can name your constants in all capital letters as recommended in VBScript Coding Conventions. In either case, it is a good idea to differentiate constants from variables. This eliminates confusion as you develop more complex scripts.Dim CutoffDate CutOffDate = #12-21-96#
© 1996 by Microsoft Corporation.