'********************************************************************

'*

'* Function Modulus

'*

'*   Author: NetworkAdminKB.com

'*  Created: 2004-12-21

'* Modified: 2008-12-07

'*

'* Purpose: Divides two numbers and returns only the remainder. This

'*            replaces the normal VBScript MOD Function and has the

'*            following benefits:

'*            1) It overcomes the VBScript MOD Functions limitation

'*                on numbers larger/smaller than +/- 2,147,483,647

'*            2) The limitation on this function is:

'*                 +/- 9,007,199,254,740,991

'*

'* Input:   numAny   A whole number of any size.

'*          numDiv   A whole number that will be used as the divisor.

'*

'* Output:  The remainder of the divided numbers.

'*          Returns Empty if an Error Occurs

'*

'* Changes:

'* 2008-05-08: Simplified procedure using Fix

'* 2008-12-07: Added check fo numDiv = 0

'********************************************************************

Function Modulus(ByVal numAny, ByVal numDiv)

  'Version: 1.4 2008-12-07

  Const maxNum = 9007199254740991

  If numAny > CDbl(maxNum) Then

    Wscript.Echo "Modulus Error: ", _

    "The divided number cannot be greater/less than +/- 9,007,199,254,740,991"

    Modulus = Empty

    Exit Function

  End If 'numAny > maxNum

  If numDiv = 0 Then

    Wscript.Echo "Modulus Error: The divisor (numDiv) is zero (0)."

    Modulus = Empty

    Exit Function

  End If 'numDiv = 0

  numAny = Fix(CDbl(numAny))

  numDiv = Fix(CDbl(numDiv))

  Modulus = numAny - Fix(numAny/numDiv) * numDiv

End Function 'Modulus

Article ID: 408, Created On: 9/25/2011, Modified: 9/25/2011