VBS TUTORIAL: VBScript statement-const statement _vbs

Source: Internet
Author: User
Tags arithmetic operators constant logical operators naming convention visibility

Const statement

Declares constants that are used in place of literal values.

 [Public | Private] Const constname = expression

Parameters

Public

Options available. This keyword is used to declare constants that can be used in all procedures in all scripts at the script level. Not allowed for use in procedures.

Private

Options available. This keyword is used to declare constants in the script level that are available only in the script in which the declaration resides. Not allowed for use in procedures.

Constname

Required option. The name of the constant, according to the standard variable naming convention.

Expression

Required option. Text or other constants, or any combination of arithmetic operators and logical operators except is.

Description

Constants are public by default. Constants in the process are always proprietary and their visibility cannot be changed. In script, you can change the default value of script-level constant visibility by using the Private keyword.

To declare several constants in the same row, you can assign each constant to separate values with commas. When declaring a constant in this way, if the public or Private keyword is used, the keyword is valid for all constants in the row.

variables, user-defined functions, or VBScript intrinsic functions (such as Chr) cannot be used in a constant declaration. By definition, they cannot be constants. In addition, you cannot create constants from an expression that contains an operator, that is, only simple constants are allowed. A constant declared in a Sub or Function procedure is a local constant of the procedure. A constant declared outside a procedure is a global constant in the script where the declaration resides. Constants can be used wherever an expression is used. The following code provides an example of how to use the Const statement:

Const MyVar = 459constants are public by default  . Const MyString = "HELP"  defines a private constant. Const MyStr = "Hello", MyNumber = 3.4567 ' define multiple constants on a single line.  

Note that constants allow the script to support itself and are easy to modify. Unlike variables, constants cannot be inadvertently modified while the script is running.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.