Rem Operator

Divides two numbers and returns only the remainder.

Syntax

Operator construct

expression_1 Rem expression_2

Function construct

Rem ( expression_1, expression_2 )

Parts

expression_1
A numeric expression.
expression_2
A numeric expression.

Instructions

The result is the remainder after expression_1 is divided by expression_2. For example, the expression 42 Rem 5 gives a result of 2.

The result has the same sign as expression_2. Compared to Rem, the result of the related operator Mod gets the sign of its first number. But it can be easy to select the correct operator for the given conditions. The letter “M” is nearer to the number that gives the result its sign.

Data types

TODO

Trying to divide by zero

If expression_2 is zero, the result of Rem is related to the data type of its expressions and which construct you use:

Examples

TODO

Program Example
#Debug.PrintLine "42 Rem 5 = " & 42 Rem 5
#Debug.PrintLine "-42 Rem 5 = " & -42 Rem 5
#Debug.PrintLine "42 Rem -5 = " & 42 Rem -5
#Debug.PrintLine "-42 Rem -5 = " & -42 Rem -5
After run
42 Rem 5 = 2
-42 Rem 5 = 2
42 Rem -5 = -2
-42 Rem -5 = -2

See also