Английский язык в информационных технологиях. Демкина Л.М. - 45 стр.

UptoLike

Составители: 

47
You can also declare a variable implicitly by simply using its name in your script. That's not
generally a good practice because you could misspell the variable name in one or more
places, causing unexpected results when your script is run. For that reason, the Option
Explicit statement is available to require explicit declaration of all variables. The Option
Explicit statement should be the first statement in your script.
Naming Restrictions
Variable names follow the standard rules for naming anything in VBScript. A variable
name:
Must begin with an alphabetic character.
Cannot contain an embedded period.
Must not exceed 255 characters.
Must be unique in the scope in which it is declared.
Scope and Lifetime of Variables
A variable's scope is determined by where you declare it. When you declare a variable
within a procedure, only code within that procedure can access or change the value of that
variable. It has local scope and is called a procedure-level variable. If you declare a variable
outside a procedure, you make it recognizable to all the procedures in your script. This is a
script-level variable, and it has script-level scope.
How long a variable exists is its lifetime. The lifetime of a script-level variable extends from
the time it's declared until the time the script is finished running. At procedure level, a
variable exists only as long as you are in the procedure. When the procedure exits, the
variable is destroyed. Local variables are ideal as temporary storage space when a procedure
is executing. You can have local variables of the same name in several different procedures
because each is recognized only by the procedure in which it is declared.
Assigning Values to Variables
Values are assigned to variables creating an expression as follows: the variable is on the left
side of the expression and the value you want to assign to the variable is on the right. For
example:
B = 200
Scalar Variables and Array Variables
Much of the time, you just want to assign a single value to a variable you've declared. A
variable containing a single value is a scalar variable. Other times, it's convenient to assign
more than one related value to a single variable. Then you can create a variable that can
contain a series of values. This is called an array variable. Array variables and scalar
variables are declared in the same way, except that the declaration of an array variable uses
parentheses ( ) following the variable name. In the following example, a single-dimension
array containing 11 elements is declared:
Dim A(10)
Although the number shown in the parentheses is 10, all arrays in VBScript are zero-based,
so this array actually contains 11 elements. In a zero-based array, the number of array
elements is always the number shown in parentheses plus one. This kind of array is called a
fixed-size array.
      You can also declare a variable implicitly by simply using its name in your script. That's not
      generally a good practice because you could misspell the variable name in one or more
      places, causing unexpected results when your script is run. For that reason, the Option
      Explicit statement is available to require explicit declaration of all variables. The Option
      Explicit statement should be the first statement in your script.
Naming Restrictions
      Variable names follow the standard rules for naming anything in VBScript. A variable
      name:
          •   Must begin with an alphabetic character.
          •   Cannot contain an embedded period.
          •   Must not exceed 255 characters.
          •   Must be unique in the scope in which it is declared.

Scope and Lifetime of Variables
      A variable's scope is determined by where you declare it. When you declare a variable
      within a procedure, only code within that procedure can access or change the value of that
      variable. It has local scope and is called a procedure-level variable. If you declare a variable
      outside a procedure, you make it recognizable to all the procedures in your script. This is a
      script-level variable, and it has script-level scope.
      How long a variable exists is its lifetime. The lifetime of a script-level variable extends from
      the time it's declared until the time the script is finished running. At procedure level, a
      variable exists only as long as you are in the procedure. When the procedure exits, the
      variable is destroyed. Local variables are ideal as temporary storage space when a procedure
      is executing. You can have local variables of the same name in several different procedures
      because each is recognized only by the procedure in which it is declared.

Assigning Values to Variables
      Values are assigned to variables creating an expression as follows: the variable is on the left
      side of the expression and the value you want to assign to the variable is on the right. For
      example:
              B = 200
Scalar Variables and Array Variables
      Much of the time, you just want to assign a single value to a variable you've declared. A
      variable containing a single value is a scalar variable. Other times, it's convenient to assign
      more than one related value to a single variable. Then you can create a variable that can
      contain a series of values. This is called an array variable. Array variables and scalar
      variables are declared in the same way, except that the declaration of an array variable uses
      parentheses ( ) following the variable name. In the following example, a single-dimension
      array containing 11 elements is declared:
              Dim A(10)
      Although the number shown in the parentheses is 10, all arrays in VBScript are zero-based,
      so this array actually contains 11 elements. In a zero-based array, the number of array
      elements is always the number shown in parentheses plus one. This kind of array is called a
      fixed-size array.


                                                    47