- 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.
- While naming the constants, you need to be careful not to use the predefined VB Script constants.Otherwise it will throw an error.
- The best preventive measure is to avoid names starting with vb because all VB Script predefined constants start with vb.
- We create user-defined constants in VBScript using the Const statement. Using the Const statement, we can create string or numeric constants with meaningful names and assign them literal values.
- Const statement
Const MyString = "This is my string."
Const MyAge =25
Const CutoffDate = #6-1-97#
- Note that String literal is enclosed in quotation marks (" "). Date literals and time literals are Represented by enclosing them in number signs (#).
- We declare multiple constants by separating each constant name and value with a comma.
Const price= 100, city= "Bengaluru", x= 25
The Constant can be of type Public or Private.
The Use of
Public or Private is Optional.
The Public constants are available for all the
scripts and procedures while the Private Constants are available within the
procedure or Class.
One can assign any value such as number, String or Date to
the declared Constant.
No comments:
Post a Comment