为变量赋值

为创建表达式的变量赋值的方式如下:变量位于表达式的左侧,要赋给变量的值位于右侧。

以下示例说明了为变量赋值的用法:

示例 1

B = 200  'Assigns the value 200 to the variable B.
Dim A
A = 100   'Assigns the value 100 to the variable A.

示例 2

Dim Name
Name = "Alice"   ' Assigns the string "Alice" to the variable Name.

示例 3

Dim IsActive
IsActive = True   ' Assigns the Boolean value True to the variable IsActive.

示例 4

Dim X, Y, Z
X = 5
Y = 10
Z = X + Y   ' Assigns the result of the expression (X + Y) to the variable Z.

示例 5

Dim CurrentDate
CurrentDate = Date   ' Assigns the current system date to the variable CurrentDate.

示例 6

Dim A, B
A = 200   ' Assigns the value 200 to the variable A.
B = A     ' Assigns the value of A to the variable B.