Suite101

Variables. Constants


© Maxim Karetnikov

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.

NOTE. In Version 5.0 of VBScript one can create string or numeric constants using the Const statement. For example:
Const LightSpeed

LightSpeed = 300000

The earlier versions of VBScript does not provide support for constants, such as you find in other programming languages.

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 Conventions

The 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 Conventions

For purposes of readability and consistency, use the prefixes listed in the following table, along with descriptive names for variables in your VBScript code.

Go To Page: 1 2


Post this Article to facebook Add this Article to del.icio.us! Digg this Article furl this Article Add this Article to Reddit Add this Article to Technorati Add this Article to Newsvine Add this Article to Windows Live Add this Article to Yahoo Add this Article to StumbleUpon Add this Article to BlinkLists Add this Article to Spurl Add this Article to Google Add this Article to Ask Add this Article to Squidoo



Subtype Prefix Example
Boolean bln blnFound
Byte byt bytRasterData
Date (Time) dtm dtmStart
Double dbl