- VBScript - Date
- VBScript - Arrays
- VBScript - Strings
- VBScript - Numbers
- VBScript - Cookies
- VBScript - Events
- VBScript - Loops
- VBScript - Decisions
- VBScript - Operators
- VBScript - Constants
- VBScript - Variables
- VBScript - Placement
- VBScript - Enabling
- VBScript - Syntax
- VBScript - Overview
- VBScript - Home
VBScript Advanced
- VBScript - Misc Statements
- VBScript - Error Handling
- VBScript - Reg Expressions
- VBScript - Object Oriented
- VBScript - Dialog Boxes
- VBScript - Procedures
VBScript Useful Resources
- VBScript - Discussion
- VBScript - Useful Resources
- VBScript - Quick Guide
- VBScript - Questions and Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
VBScript - Constants
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.
Declaring Constants
Syntax
[Pubpc | Private] Const Constant_Name = Value
The Constant can be of type Pubpc or Private. The Use of Pubpc or Private is Optional. The Pubpc 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.
Example 1
In this example, the value of pi is 3.4 and it displays the area of the circle in a message box.
<!DOCTYPE html> <html> <body> <script language = "vbscript" type = "text/vbscript"> Dim intRadius intRadius = 20 const pi = 3.14 Area = pi*intRadius*intRadius Msgbox Area </script> </body> </html>
Example 2
The below example illustrates how to assign a String and Date Value to a Constant.
<!DOCTYPE html> <html> <body> <script language = "vbscript" type = "text/vbscript"> Const myString = "VBScript" Const myDate = #01/01/2050# Msgbox myString Msgbox myDate </script> </body> </html>
Example 3
In the below example, the user tries to change the Constant Value; hence, it will end up with an Execution Error.
<!DOCTYPE html> <html> <body> <script language = "vbscript" type = "text/vbscript"> Dim intRadius intRadius = 20 const pi = 3.14 pi = pi*pi pi VALUE CANNOT BE CHANGED.THROWS ERROR Area = pi*intRadius*intRadius Msgbox Area </script> </body> </html>Advertisements