Results 1 to 5 of 5
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Evenly Divisible By a Number? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    What is the best command syntax to use to determine if a number is evenly divisible by 3.00

    9.00 / 3.00 = 3 is OK

    8.00 / 3.00 = 2.66 NG

    10.00 / 3.00 = 3.33 NG

    Thanks, John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Evenly Divisible By a Number? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    You can use the Mod operator: The result of a Mod b is the remainder of a when divided by b (using integer division), so a is evenly divisible by b if a Mod b = 0.

    9 Mod 3 = 0
    8 Mod 3 = 2
    10 Mod 3 = 1

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Evenly Divisible By a Number? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    Having problems with following logic"

    The 1st MsgBox = 9 and 2nd MsgBox = 3 is triggering

    MsgBox "Current Price dose not contain the proper surcharge: " path,

    Shouldn’t it trigger

    MsgBox "Current Price look OK: "

    What am I doing wrong?

    Thanks

    John

    <pre>Private Sub curPrice_BeforeUpdate(Cancel As Integer)

    ‘this reveals 9
    MsgBox (Nz(Me.curPrice, 0) _
    - Nz(Me.curAmount, 0)) _
    + Nz(DLookup("[curSurcharge]", "[tbl_RevGLDesc]", _
    "[lngRevGLDescID] = RC "), 0)

    ‘this reveals 3
    MsgBox Nz(DLookup("[curSurcharge]", "[tbl_RevGLDesc]", _
    "[lngRevGLDescID] = RC "), 0)

    If (Nz(Me.curPrice, 0) _
    - Nz(Me.curAmount, 0)) _
    + Nz(DLookup("[curSurcharge]", "[tbl_RevGLDesc]", _
    "[lngRevGLDescID] = RC "), 0) _
    Mod _
    Nz(DLookup("[curSurcharge]", "[tbl_RevGLDesc]", _
    "[lngRevGLDescID] = RC "), 0) = 0 Then
    MsgBox "Current Price look OK: "

    Else

    MsgBox "Current Price dose not contain the proper surcharge: "
    Cancel = True
    Exit Sub
    </pre>


  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Evenly Divisible By a Number? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    You probably have to place the parentheses differently:
    <pre>If (Nz(Me.curPrice, 0) _
    - Nz(Me.curAmount, 0) _
    + Nz(DLookup("[curSurcharge]", "[tbl_RevGLDesc]", _
    "[lngRevGLDescID] = RC "), 0)) _
    Mod _
    Nz(DLookup("[curSurcharge]", "[tbl_RevGLDesc]", _
    "[lngRevGLDescID] = RC "), 0) = 0 Then
    MsgBox "Current Price look OK: "
    </pre>

    If that doesn't work either, it may be caused by rounding problems.

  5. #5
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,878
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Evenly Divisible By a Number? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    This worked, Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •