= (statement)


variable = expression


Assigns the result of an expression to a variable.


When assigning expressions to variables, internal type conversions are performed automatically between any two numeric quantities. Thus, you can freely assign numeric quantities without regard to type conversions. However, it is possible for an overflow error to occur when converting from larger to smaller types. This occurs when the larger type contains a numeric quantity that cannot be represented by the smaller type. For example, the following code will produce a runtime error:

  Dim amount As Long
  Dim quantity As Integer

  amount = 400123    'Assign a value out of range for int.
  quantity = amount   'Attempt to assign to Integer.

When performing an automatic data conversion, underflow is not an error.


The assignment operator (=) cannot be used to assign objects. Use the Set statement instead.


Sub Main()
  a$ = "This is a string"
  b% = 100
  c# = 1213.3443
  MsgBox a$ & "," & b% & "," & c#
End Sub

See Also

Let (statement); Operator Precedence (topic); Set (statement); Expression Evaluation (topic).

More information