7 Replies Latest reply on May 28, 2015 7:43 AM by mleering

    Need help simplifying an adding code

    ElliotFriedman

      Title

      Need help simplifying an adding code

      Post

      I'm currently working on a database (which I didn't originally set up) and I'm trying to update some code to account for further fields added.

      The existing code seems quite long winded and I'm convinced there's an easier and much shorter way to make the same calculation.

      Currently, the code adds up 5 fields but I'd like to accommodate up to 8 and easily add more in the future.

      If anyone could help me with simplifying the following, it would be much appreciated!

      To avoid spam, here's the code: http://pastebin.com/XLcqjHnL

        • 1. Re: Need help simplifying an adding code
          mleering
          My approach would be to make x number of simple new calculation fields. For instance client_calc1 If (Client module 1 = "1" ; Client Hours 1). Once you have those calcs made, then your end formula is just client_calc1+client_calc2+client_calc3...and so on.
          • 2. Re: Need help simplifying an adding code
            ElliotFriedman

            Thanks for your response Matthew!

            This database has 8 "Client hours" sections, each containing a drop down menu to select the module:

            http://i.imgur.com/u47FXHY.png

            Once the fields on the left have been filled in, the total calculation is displayed on the right in the relevant module.

            Would your approach work considering the above? Would I have to create custom functions for this?

            I'm a huge FileMaker Pro newbie so the more help the better!

            • 3. Re: Need help simplifying an adding code
              mleering

              Hey no problem Elliot.

              I see no reason why the approach I suggested wouldn't work here.
              Question for you though... how do the "Client Module" fields attain a value of "1"?
              Depending on how that happens, and if those fields are used for other reasons also, this has the potential to be simplified even further.

              • 4. Re: Need help simplifying an adding code
                ElliotFriedman

                The simpler the better!

                This system is for student therapists seeing multiple clients. Each student has a portfolio page. Within that page is an array of 25 possible client entries. Within each client entry (image) are 8 boxes (previously 5) to log client work hours. There are 8 boxes to account for sporadic hour submissions and supervisor signatures.

                The value of "1" is the module (or year) that the student is in. That value goes up to "4" to mirror the final year group, module 4.

                The code that I pastebinned has 3 more versions for each relative module: ( Client module 1 = "2" ), ( Client module 1 = "3" ) and ( Client module 1 = "4" ). This allows for 4 separate module calculations (on the right of this image).

                It's probably confusing to see ( Client module 1 = "4" ) but the 1 in this instance relates to the input field and not the actual student module!

                Hopefully this makes the system seem a bit clearer!

                • 5. Re: Need help simplifying an adding code
                  mleering

                  Okay, I follow most of that.
                  ;)

                  The reason I asked was because I was thinking those fields might simply just be calculations that return 1 if there was a signature in the corresponding field.  If that were the case, and you didn't need the field elsewhere, then we could have done some further reduction.

                  Since it's not though, I offer you yet another variation of my suggestion.
                  I figure that since you're already up to 8 modules (from 5), and you still want to leave room for growth, you might not want to keep on adding so many fields.  Another way that you could tackle this is by using just one calculation field (possibly the same one whose formula you originally posted to pastebin).  This formula is still somewhat lengthy, but a lot easier to manage in my opinion.  It uses the "Let" function which has 2 parts to it.  The top part (within the square brackets) is where you can define your variables.  Those variables can be used in the formula that appears within the bottom part of the Let statement.

                  http://pastebin.com/GGpnLkHh

                  • 6. Re: Need help simplifying an adding code
                    ElliotFriedman

                    That worked perfectly! This is far more efficient and much easier to work with. Thanks for your help and swift responses, Matthew. Much appreciated! :).

                    • 7. Re: Need help simplifying an adding code
                      mleering

                      No problem Elliot, glad I could be of some help.

                      Happy FileMaking