Export (0) Print
Expand All

+= Operator

Adds the value of an expression to the value of a variable and assigns the result to the variable. Also concatenates a String expression to a String variable and assigns the result to the variable.

variable += expression

Parts

variable
Required. Any numeric or String variable.
expression
Required. Any numeric or String expression.

Remarks

This statement will implicitly perform widening but not narrowing conversions if the compilation environment is enforcing strict semantics. For details on these conversions, see Widening and Narrowing Conversions. If permissive semantics are allowed, the operator will implicitly perform a variety of string and numeric conversions. These conversions are identical to the conversions described for the + operator. For details on how these conversions are performed, see + Operator. For more information on strict and permissive semantics, see Option Strict Statement.

Example

These examples use the += operator to combine the value of one variable with another. In the first example, += is used with numeric variables to add one value to another. In the second example, += is used with String variables to concatenate one value with another. In both cases, the result is assigned to the first variable.

Dim var1 As Integer = 10
Dim var2 As Integer = 3
var1 += var2   ' The value of var1 is now 13.

' This example uses string variables.
Dim var1 As String = "10"
Dim var2 As String = "3"
var1 += var2   ' The value of var1 is now "103".

See Also

+ Operator | -= Operator | Assignment Operators | Arithmetic Operators | Concatenation Operators | Operator Precedence in Visual Basic | Operators Listed by Functionality | Assignment Statements

Show:
© 2014 Microsoft