In our Variables tutorial we have shown you, how variables are used as containers to store information. Well so does a constant. The main difference between constants and variables is that constant value can not be changed in the process of running program. Constants always keep their value assigned while declaration.
Have a look at the following example where the value of the myText variable changes throughout the script.
|
The value stored in a constant cannot be changed after it has been declared. If we attempt to re-assign the value of the constant as we did with the value of the variable we’ll get a run time error. To declare a constant in VBScript we use the Const keyword.
|
The following example demonstrates the advantage of constants: during the calculations with number PI, you can type in your code only constants name instead of typing this number each time.
|