The best VBScript variable Tutorial In 2024, In this tutorial you can learn Try - Example (only for IE),Remember in school algebra you learned?,VBScript variable,Statement (Creating) VBScript variable,Assign values to variables,Lifetime of variables,VBScript array variable,Examples (only for IE),
Variable is a "container" for storing information.
Creating and changing variables
How to create a variable and assign to it, and then change its value.
Insert variable values in a text
How to insert variable values in some text.
Creating an array
The array is used to store a series of related items. This example demonstrates how to create a storage array name.
Remember in school algebra you learned? x = 5, y = 6, z = x + y
do you remember? A letter (such as x) can save a value (such as 5), and can use the information above to calculate the value of z is 11.
These letters are calledvariables, variables can be used to hold values (x = 5) or expressions (z = x + y).
Compared with algebraic, VBScript variable used to hold values or expressions.
Variable can have a short name, like x, or a more descriptive name, such as carname.
VBScript variable name rule:
In VBScript, all variables are associated with the type ofvariantcan store different types of data.
Create the VBScript variable is usually referred to as "declaration" variable.
You can Dim, Public or Private statement to declare VBScript variables. As follows:
Now that you have created two variables. It is the name of the variable "x" and "carname".
You can also use it in the script name to declare variables. As follows:
Now you've created a variable. Name of the variable is "carname". Then, this approach is not a good idea since you may misspell the variable name in the script, that can cause strange results when the script runs.
If you misspell a variable name, such as "carname" variable is misspelled as "carnime", the script automatically creates a new variable named "carnime" of. In order to prevent a script to do this, you can use the Option Explicit statement. If you use this statement, you must use the dim, public or private statement to declare all the variables.
To the top of the Option Explicit statement is placed in the script, as follows:
You can assign a variable as follows:
Variable names are on the left side of the expression, you need to assign the value of the variable on the right side in the expression. Variable "carname" The value is now "Volvo", the variable "x" is the value of "10."
Live variable refers to the length of time it can exist.
When you declare a variable in a subroutine, variables can only be accessed within the program. When you exit the program, the variable will fail. Such variables are called local variables. You can use the same name as a local variable in a different routine, because each variable declaration can only be identified within its program.
If you declare a variable outside of a subroutine, all routines on your page can access it. Survival of these variables begins they are declared, and ends the page is closed.
Variable is used in a single array of a plurality of values stored in the variable.
In the following example, we declare an array contains three elements:
Figures in parentheses show the 2. Array indices start at 0, so the array contains three elements. It is the capacity of a fixed array. You can assign each element of the data array, as follows:
Similarly, by using the following labels are particular array element, you can retrieve the value of any element. As follows:
You can use up to 60 in one dimension array. The method of multidimensional array is in parentheses with commas to separate numbers. Here, we declare a two-dimensional array contains five rows of seven:
For the two-digit group assignment: