VBScript data types
VBScript has only one data type, namely Variant, called variant type. Varriant is a special data type that can contain different categories of information depending on how it is used. Because Variant is the only data type in VBScript, it is also the data type of the return value of all functions in VBScript.
The simplest Variant can contain numeric or string information. Variant is used as a numeric process when used in a numeric context and as a numeric process when used in a string context. That is, if data that looks like a number is used, VBScript assumes it is a number and handles it in a way that applies to the number. Similarly, if the data used is only possible strings, VBScript will be processed by string. You can also include numbers in quotes ("") to make them a string.
The type of value information contained in Variant is called a subtype. In most cases, the required data can be put into Variant, and Variant also operates in the way that best applies to its data.
Data subtypes that Variant contains
VBScript variables and constants
Variables are convenient placeholders that reference computer memory addresses that can store program information that can be changed when the script runs. For example, you can create a variable called ClickCount to store the number of times a user clicks an object on a web page. Using variables does not require understanding the address of the variable in computer memory. You can view or more value of the variable by referencing the variable through the variable name. There is only one basic data type in VBScript, namely Variant, so the data type of all variables is Variant.
1. Variable naming rules
Variable naming must follow the standard naming rules of VBScript:
The first character must be a letter. Cannot contain embedded periods (.). The length cannot exceed 255 characters. Must be unique within the declared scope. Can't be the same as the keywords in VBScript.
2. Declare variables
In VBScript, Dim statements, Public statements, and Private statements are usually used to explicitly declare variables and allocate storage space. Its syntax format is:
{Dim|Private|Public} <Variable Name 1> [,<Variable Name 2>] [,<Variable Name 3>]...[,<Variable Name>]
illustrate:
(1) The variables declared by the Public statement can be used in all procedures in all scripts;
(2) Script-level variables declared with Dim can be used for all processes in scripts, but process energy variables are only used in processes at levels;
(3) The variable declared by the Private statement can only be used in the script that declares the variable.
(4) When declaring multiple variables, use commas to separate the variables. Such as: Dim a,b,c,d
Another way is to implicitly declare variables by using variable names directly in the script. This is usually not a good habit, as this can sometimes lead to unexpected results when running scripts due to misspelling of variable names. Therefore, it is best to declare all variables using the Option Explicit statement and use them as the first statement of the script. (i.e. it must appear before any HTML identifier or other VBScript commands, otherwise the statement will be considered illegal.