Microsoft Office 2000/Visual Basic Programmer's Guide   

Using the Mod Operator

The Mod operator divides two numbers and returns the remainder. It's useful when you need to 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

The IsFactor procedure is available in the modNumbers module in VBA.mdb in the ODETools\V9\Samples\OPG\Samples\CH07 subfolder on the Office 2000 Developer CD-ROM.