VBScript Tutorial Three

Source: Internet
Author: User
Tags scalar
VBScript variables
A variable is a handy placeholder for referencing a computer's memory address that can store program information that can be changed while the script is running. For example, you can create a variable named Clickcount to store the number of times a user clicks an object on a Web page. Using a variable does not require an understanding of the variable's address in the computer's memory, as long as you can view or change the value of the variable by referencing the variable name. There is only one basic data type in VBScript, a variant, so all variables have a variant of the data type.
declaring variables
One way to declare a variable is to use the DIM statement, public statement, and Private statement to explicitly declare the variable in the script. For example:
Dim Degreesfahrenheit
When declaring multiple variables, use commas to separate the variables. For example:
Dim top, Bottom, left, right
Another way is to implicitly declare a variable by using the variable name directly in the script. This is usually not a good habit, because it can sometimes cause unexpected results when the script is run because the variable name is spelled incorrectly. Therefore, it is best to explicitly declare all variables using the Option Explicit statement as the first statement of the script.
Naming rules
Variable naming must follow VBScript's standard naming conventions. Variable naming must follow:
The first character must be a letter.
Cannot contain an embedded period.
The length cannot exceed 255 characters.
Must be unique within the declared scope.
Scope and lifetime of variables
The scope of a variable is determined by the position in which it is declared. If you declare a variable in a procedure, only the code in the procedure can access or change the value of the variable, at which point the variable has a local scope and is called a procedure-level variable. If you declare a variable outside of a procedure, the variable can be recognized by all procedures in the script, called a script-level variable, with a scripting-level scope.
The time at which a variable exists is called a survival period. The lifetime of a script-level variable is from the moment it is declared until the end of the script run. For a procedure-level variable, its lifetime is only the time that the process is running, and the variable disappears when the process ends. Local variables are ideal temporary storage space when executing a procedure. Local variables of the same name can be used in different procedures, because each local variable is recognized only by the procedure that declares it.
Assigning values to variables
Create an expression of the following form to assign a value to a variable: The variable is on the left side of the expression, and the value to assign is to the right of the expression. For example:
B = 200
scalar variables and array variables
In most cases, you simply 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 related values to a variable, so you can create a variable that contains a series of values, called an array variable. An array variable and a scalar variable are declared in the same way, except that the variable name is followed by parentheses () when the array variable is declared. The following example declares a one-dimensional array that contains 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.