VBScript variable

Source: Internet
Author: User
Tags scalar
What is a variable?
A variable is a convenient placeholder used to reference the computer memory address, which can store information about programs that can be changed during Script running. For example, you can create a variable named ClickCount to store the number of times a user clicks an object on the Web page. When using a variable, you do not need to know the address of the variable in computer memory. You only need to reference the variable through the variable name to view or change the value of the variable. In VBScript, there is only one basic data type, namely Variant. Therefore, the data types of all variables are Variant.
Declare variables
One way to declare variables is to explicitly declare variables in scripts using Dim statements, Public statements, and Private statements. For example:
Dim DegreesFahrenheit
When multiple variables are declared, use commas to separate the variables. For example:
Dim Top, Bottom, Left, Right
Another way is to implicitly declare a variable by directly using the variable name in the Script. This is usually not a good habit, because sometimes unexpected results occur when running scripts due to misspelling of variable names. Therefore, it is best to use the Option Explicit statement to explicitly declare all variables and use them as the first statement of the Script.
Naming rules
Variable naming must follow the standard naming rules of VBScript. Variable naming must follow:
The first character must be a letter.
Cannot contain embedded periods.
It cannot exceed 255 characters.
It must be unique within the declared scope.
Scope and survival of variables
The scope of a variable is determined by its position. If a variable is declared during the process, only the code in the process can access or change the value. At this time, the variable has a local scope and is called a process-level variable. If a variable is declared outside the process, the variable can be recognized by all processes in the Script. It is called a Script-level variable and has a Script-level scope.
The time when a variable exists is called the retention period. The Script-level variable retention period starts from the declared moment until the Script operation ends. For a process-level variable, its survival period is only the time when the process runs. After the process ends, the variable disappears. Local variables are ideal for temporary storage during execution. You can use local variables with the same name in different processes, because each local variable is identified only by the declared process.
Assign values to variables
Create an expression in the following form to assign a value to the variable: the variable is on the left side of the expression, and the value to be assigned is on the right side of the expression. For example:
B = 200
Scalar variables and array variables
In most cases, you only need to assign a value to the declared variable. A variable that contains only one value is called a scalar variable. Sometimes it is more convenient to assign multiple values to a variable. Therefore, you can create a variable that contains a series of values, called an array variable. Array variables and scalar variables are declared in the same way. The only difference is that when an array variable is declared, the variable name is enclosed by parentheses (). The following example declares a one-dimensional array containing 11 elements:

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.