One line of math perhaps?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Remington
    New Member
    • Jan 2007
    • 20

    One line of math perhaps?

    I have a somewhat simple math function i would like to preform. For every 10 units selected into one field, I need 3 subtracted from. So if 30 units is selected, then 9 is subtracted from that 30 before being dumped into its resting field.

    Hopefully its not too complicated, but it was more then I could figure out at the time.
  • ADezii
    Recognized Expert Expert
    • Apr 2006
    • 8834

    #2
    Originally posted by Remington
    I have a somewhat simple math function i would like to preform. For every 10 units selected into one field, I need 3 subtracted from. So if 30 units is selected, then 9 is subtracted from that 30 before being dumped into its resting field.

    Hopefully its not too complicated, but it was more then I could figure out at the time.
    Code:
    UnitsToDump = (UnitsSelected \ 10) * 3

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32633

      #3
      Is this on a pro rata basis?
      Or is it necessary to reach a multiple of ten before any is subtracted (in other words does a value of 29 return 8.7 or simply 6)?

      Comment

      • Remington
        New Member
        • Jan 2007
        • 20

        #4
        Originally posted by NeoPa
        Is this on a pro rata basis?
        Or is it necessary to reach a multiple of ten before any is subtracted (in other words does a value of 29 return 8.7 or simply 6)?
        Every 10 units, i need to subtract 3 Units. If 9 or 8 units is selected, then nothing needs to be done, other then keeping that 9 or 8. If 11 is done, then i need the 3 subtracted for the 10 then added with 1.

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32633

          #5
          In that case ADezii's answer is right for you :)

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            UnitsToDump = Int(UnitsSelect ed \ 10) * 3

            Comment

            • NeoPa
              Recognized Expert Moderator MVP
              • Oct 2006
              • 32633

              #7
              Originally posted by Rabbit
              UnitsToDump = Int(UnitsSelect ed \ 10) * 3
              In this case the Int() would be superfluous as the '\' (not '/' notice) is an integer division operator.

              Comment

              • Rabbit
                Recognized Expert MVP
                • Jan 2007
                • 12517

                #8
                I did not know that. Something learned.

                Comment

                • Remington
                  New Member
                  • Jan 2007
                  • 20

                  #9
                  Originally posted by NeoPa
                  In this case the Int() would be superfluous as the '\' (not '/' notice) is an integer division operator.

                  Umm..what does superfluous mean? no need for the ( ) or should i not even worry about it?

                  Comment

                  • Rabbit
                    Recognized Expert MVP
                    • Jan 2007
                    • 12517

                    #10
                    It means just use UnitsToDump = (UnitsSelected \ 10) * 3 because the "\" operator does the same thing as the Int() function.

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32633

                      #11
                      Full member Rabbit - nice ;)

                      Remington,
                      Superfluous == More than is necessary.
                      Int(n) strips any fractional part from n.
                      x \ y is integer divide so essentially, after the division the fractional part is stripped.
                      Thus, the Int() in Int(x \ y) would be superfluous.

                      This was not directed at answering the question so it's not critical that you follow this dialogue. It was communication between Rabbit & myself discussing the solutions already provided.

                      Comment

                      Working...