Sun Chili!Soft ASP Sun Chili!Soft
ASP Sun Microsystems

 

VBScript Const Statement

Declares constants for use in place of literal values.

Syntax: VBScript Const Statement

[Public | Private] Const constname = expression

Arguments: VBScript Const Statement

Public

A keyword used at script level to declare constants that are available to all procedures in all scripts. Not allowed in procedures. Optional.

Private

A keyword used at script level to declare constants that are available only within the script where the declaration is made. Not allowed in procedures. Optional.

constname

The name of the constant; follows standard variable naming conventions. Required.

expression

A literal or other constant, or any combination that includes all arithmetic or logical operators except Is. Required.

Remarks: VBScript Const Statement

Constants are public by default. Within procedures, constants are always private; their visibility can't be changed. Within a script, the default visibility of a script-level constant can be changed using the Private keyword.

To combine several constant declarations on the same line, separate each constant assignment with a comma. When constant declarations are combined in this way, the Public or Private keyword, if used, applies to all of them.

You can't use variables, user-defined functions, or intrinsic VBScript functions (such as Chr) in constant declarations. By definition, they can't be constants. You also can't create a constant from any expression that involves an operator; that is, only simple constants are allowed. Constants declared in a Sub or Function procedure are local to that procedure. A constant declared outside a procedure is defined throughout the script in which it is declared. You can use constants anywhere you can use an expression. The following code illustrates the use of the Const statement:

Const MyVar = 459   ' Constants are Public by default.

Private Const MyString = "HELP"   ' Declare Private constant.

Const MyStr = "Hello", MyNumber = 3.4567   ' Declare multiple constants on same line.

Tip

Constants can make your scripts self-documenting and easy to modify. Unlike variables, constants can't be inadvertently changed while your script is running.

Copyright 2002 Sun Microsystems, Inc. All rights reserved. Legal Notice.