Home page   WebCheatSheet.com

ASP: Constants

Constants just as variables are used to store information. The main difference between constants and variables is that constant value can not be changed in the process of running program. If we attempt to re-assign the value of the constant we'll get a run time error.

It can be mathematic constants, passwords, paths to files, etc. By using a constant you "lock in" the value which prevents you from accidentally changing it. If you want to run a program several times using a different value each time, you do not need to search throughout the entire program and change the value at each instance. You only need to change it at the beginning of the program where you set the initial value for the constant.

To declare a constant in VBScript we use the Const keyword. Have a look at the following example:

Const myConst = "myText"

'it is allowed to declare a few constants on the one line

Const PI = 3.14159, Wg  = 2.78

Next example demonstrates the advantage of constants: during the calculations with number PI, you can type in your code only constants names instead of typing this number each time.


vCircle = PI * vRadius^2

Copyright © 2005-2007 www.WebCheatSheet.com All Rights Reserved.