Visual Basic Language Reference  

\ Operator

Divides two numbers and returns an integer result.

number1 \ number2

Parts

number1
Required. Any numeric expression of an integral type.
number2
Required. Any numeric expression of an integral type.

Supported Types

Byte, Short, Integer, or Long.

Result

The result is the integer quotient of number1 and number2, dropping the remainder.

Remarks

Before division is performed, any floating-point numeric expressions are coerced to Byte, Short, Integer, or Long expressions if Option Strict is Off. If Option Strict is On, a compiler error results.

The data type of the result is Byte, Short, Integer, or Long. Any fractional portion is truncated.

If any expression is stated as Nothing, or Empty, it is treated as zero. Attempting to perform integer division by zero causes a DivideByZeroExeception to be thrown.

Example

This example uses the \ operator to perform integer division. The result is an integer representing the integer quotient of the two operands.

Dim myValue As Integer
myValue = 11 \ 4   ' Returns 2.
myValue = 9 \ 3   ' Returns 3.
myValue = 100 \ 3   ' Returns 33.
MyValue = 67 \ -3   ' Returns -22.

See Also

\= Operator | / Operator | Arithmetic Operators | Operator Precedence in Visual Basic | Operators Listed by Functionality | Arithmetic Operators