|
|
|||||||||||||||||
|
|
VBScript Constants
A constant is a named value that doesn't change throughout a script. For example, the value of the speed of light in vacuum is about 300 000 km/sec. To use this constant in a script, you simply declare it, assign it, and use it like a variable. To differentiate a value that you want to be a constant in your script, you should use your own naming conventions, so that you don't try to reassign the value of the constant that you've created. 'vbLight Speed of Light Dim vbLight vbLight = 300000 Once you set the value of the constant, you can use it in your script as if it were the actual number. Keep in mind though that constants in VBScript are essentially just variables that you don't change in your program. Unlike other languages that allow you to set the value of a constant to static, there's no way to make a variable in VBScript unchangeable.
It is a good idea to adopt a naming scheme to differentiate constants from variables. This will prevent from trying to reassign constant values to common variables and eliminates confusion in complex scripts. For example, one might want to use a "vb" prefix on constant names or you can name your constants in all capital letters as recommended in VBScript Coding Conventions. VBScript Coding ConventionsThe main reason for using a consistent set of coding conventions is to standardize the structure and coding style of a script or set of scripts so that you and others can easily read and understand the code. Using good coding conventions results in precise, readable, and unambiguous source code that is consistent with other language conventions and as intuitive as possible. Variable Naming ConventionsFor purposes of readability and consistency, use the prefixes listed in the following table, along with descriptive names for variables in your VBScript code.
| ||||||||||||||||