Monday, November 3, 2014

VBScript Constant Variable

Constant is providing a facility to declare a variable Constant. System will give run time error If user will try to initialize again.

'Constant is a named memory location used to hold a value that CANNOT be changed during the script execution.
'If a user tries to change a Constant Value, the Script execution ends up with an error.
'Constants are declared the same way the variables are declared.

Dim Var1

var1=20

Const ConsVar1 =25
'Const Dim ConsVar2 =25 ' Expected Identifier

'Const ConsVar3 ' Expected =
'ConsVar3=30


MsgBox " Normal Variable Before change "&Var1
MsgBox " Constant Variable "&ConsVar1

var1=20

'ConsVar1=20 'illegal assignment

MsgBox " Normal Variable After change "&Var1