This documentation is archived and is not being maintained.

Calculating Numeric Values

Numeric values can be calculated through the use of numeric expressions. A numeric expression is an expression that contains literals and variables representing numeric values, and operators that act upon those values. The following is an example of a numeric expression:

4 * (67 + x) ' For the purposes of this example, x = 2.

This expression evaluates to 276, which is the value of 67 plus 2, multiplied by 4.

If the numeric expression contains more than one operator, the order in which they are evaluated is determined by the rules of operator precedence. To override the rules of operator precedence, you enclose expressions in parentheses, as in the above example; such expressions are evaluated first. For more information, see Operator Precedence in Visual Basic, and Efficient Combination of Operators

You can use an assignment statement to assign the value represented by this expression to another variable, as in this example:

Dim x As Integer = 2
Dim y As Integer
y = 4 * (67 + x)

Here, the value of the expression on the right side of the operator is assigned to the variable y on the left side of the operator, so y evaluates to 276. For more information on assignment, see Assignment Statements.

See Also

Expressions | Value Comparisons | Assignment Statements | Operator Precedence in Visual Basic | Arithmetic Operators | Efficient Combination of Operators