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

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Evenly Divisible By a Number? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    Author
    Topic
    #446225

    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

    Viewing 0 reply threads
    Author
    Replies
    • #1084145

      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

      • #1084169

        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

        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
         
        • #1084171

          You probably have to place the parentheses differently:

          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: "
          

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

    Viewing 0 reply threads
    Reply To: Evenly Divisible By a Number? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: