Using the Mod Operator

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The Mod operator divides two numbers and returns the remainder. It is useful when you must determine whether two numbers divide evenly, or how close they come to dividing evenly. The Mod operator always returns an Integer or Long value, even when you divide floating-point or fixed-point numbers.

For example, the IsFactor procedure takes two arguments, a number and a potential factor, and returns True if the second argument is indeed a factor of the first. The procedure uses the Mod operator to determine whether one value divides evenly into the other.

Function IsFactor(lngNum As Long, _
                lngFactor As Long) As Boolean
              
   ' Determines whether one number is a factor of another number.
   
   IsFactor = Not CBool(lngNum Mod lngFactor)
End Function

See Also

Working with Numbers | The Integer, Long, and Byte Data Types | The Boolean Data Type | The Floating-Point Data Types | The Currency and Decimal Data Types | Conversion, Rounding, and Truncation | Formatting Numeric Values | Performing Calculations on Numeric Arrays