指派值給變數

值會指派給建立表示式的變數,如下所示:變數位於表示式的左側,而您要指派給變數的值位於右側。

下列範例說明「指派值給變數」的用法:

範例 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.