VBScript Constants and Keywords

A constant is a meaningful name that takes the place of a number or string that will never change. VBScript defines a number of intrinsic constants. For example, const pi = 3.14

Creating VBScript Constants

We can create user-defined constants in VBScript using the Const statement. Using the Const statement, you can create string or numeric constants with meaningful names and assign them literal values. For example:

After declaring a constant, if you try to change its value, then you will get an error.

We can’t use the predefined VBScript constants while naming the constants. For examples vbNewLine, vbSunday, vbArray, vbTab and so on.

You can use these predefined VBScript constants in your code as you want.

VBScript Keywords

1. Empty: The Empty keyword is used to indicate an uninitialized variable value. This is not the same thing as Null. You can use the IsEmpty Function to determine whether a variable is initialized.

2. False: The False keyword has a value equal to 0.

3. Null: The Null keyword is used to indicate that a variable contains no valid data. This is not the same thing as Empty. You can use the IsNull Function to determine whether a variable is assigned Null.

4. True: The True keyword has a value equal to 1.

5. Nothing: The Nothing keyword in VBScript is used to disassociate an object variable from any actual object. Use the Set statement to assign Nothing to an object variable. For example:

Set MyObject = Nothing

Several object variables can refer to the same actual object. When Nothing is assigned to an object variable, that variable no longer refers to any actual object.

When several object variables refer to the same object, memory and system resources associated with the object to which the variables refer are released only after all of them have been set to Nothing, either explicitly by using Set, or implicitly after the last object variable that is not set to Nothing goes out of scope.

You can use the IS Operator to determine whether an object variable is assigned Nothing, as shown in the following example.

If MyObject IS Nothing Then

About the Author

Leave Comment