Mod Operator

Divides two numbers and returns only the remainder.

Note: Mod usually operates the same as Rem. See the section TBD to know why and how to change its operation.

Syntax

Operator construct

expression_1 Mod expression_2

Function construct

Mod ( 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 Mod 5 gives a result of 2.

The result has the same sign as expression_1. Compared to Mod, the result of the related operator Rem gets the sign of its second 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 Mod is related to the data type of its expressions and which construct you use:

Examples

TODO

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

See also