Mod Operator


Mod Operator

Syntax

     Dim result As type = number1 Mod number2 


type (required)

One of the following data types: Byte, Decimal, Double, Integer, Long, Single, or Short


number1 (required; any valid numeric expression)

A numerator in a division expression


number2 (required; any valid numeric expression)

A nonzero denominator in a division expression

Description

The Mod operator returns the modulus, that is, the remainder when number1 is divided by number2. This return value is a nonnegative integral data type.

Usage at a Glance

  • Floating point numbers are rounded to integers before the division.

  • If number1 or number2 is Nothing, an error occurs.

  • The Mod operator returns the data type of number1 and number2 if they are the same type, or the widest data type of number1 and number2 if they are different.

Example

     MsgBox(10 Mod 3)   ' returns 1 

Version Differences

The Mod operator can be overloaded beginning in the 2005 edition of Visual Basic. The custom overload can assign any logic or restrictions on its use.

See Also

IEEERemainder Function




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net