13 Replies Latest reply on Jun 22, 2013 2:17 PM by doronkipper

    Solution for Toggling between Imperial and Metric Units?

    doronkipper

      Title

      Solution for Toggling between Imperial and Metric Units?

      Post

           I am designing a Filmaker Database for recording measurements.

           A simplified example of the main data entry layout:

           Height:   [feet field] FT   [inches field] IN  = [Calculation combining the feet-inches fields]

           example in use:

           Height: [ 5 ] FT  [ 11 ] IN = [ 5'11" ]

            

           Behind the scenes, I have a calculation field converting the Feet-Inches measurement to Meters.

           I'm looking for a way to create a button that toggles the data entry from Imperial units to Metric units.  The best thing I can think of is to set up the layout like this:

           Height:   [feet field] FT   [inches field] IN     [meters field] m  = [Calculation combining the feet-inches fields]  [meters field] m

           and set-up conditional formatting to make the imperial or metric field invisible when a record setting is applied.

           This is clearly not a great idea since users can still enter data in an invisible field....and there will be a big gap on the layout when one set of fields is not in use.  

           I'm trying to avoid creating 2 different layouts because the overall solution will have many measurement fields, and Ideally I'd like to be able to toggle between metric and imperial on any given measurement set.  Another wishlist item would be to be able to enter the feet-inches....and when you toggle, the meters field that appears already has the converted value...and vice versa.

           I don't know if any of this is possible....but it seems like something that should be possible with the right design.

            

           Is there any way to stack fields on a layout, and only make one visible and available for data entry based on a condition or script?

            

           I'm using Filemaker Pro 12

            

           Thanks for any advice you can provide.

            

        • 1. Re: Solution for Toggling between Imperial and Metric Units?
          JimMac

               Why not have a single field Height?

               Let the user enter  5'11" or  1.803m for the value.

               You would parse this Height Field to detect standard abbeviations and decide what Units.

               Thus....

               Even 2m9" could be used.wink

               Then you could put the Decimal Imperial AND Metric as the Calculated result.

               Jim...

          • 2. Re: Solution for Toggling between Imperial and Metric Units?
            ninja

                 For utility of stacked fields, if you choose to go that way at all, simply make all the fields the same size and make the topmost one on the stack a button that launches a script.  (remove the stacked fields from the tab order)

                 The launched script looks at whatever conditions you want, then ends in a "GoToField" step.

                 Now when a user clicks to put the cursor in the field...your script decides which of the fields to go to in the stack.

                 If doing this, you'llk also want the entry script or an OnModify script to clear values from the other fields.

            • 3. Re: Solution for Toggling between Imperial and Metric Units?
              philmodjunk

                   Or you could use a tab control with one tab for entering imperial units and another tab for metric units.

              • 4. Re: Solution for Toggling between Imperial and Metric Units?
                doronkipper

                     Thanks for all your quick replies!  

                     Jim, could you expand (or point me in the direction of a thread that explains) on what functions you would set-up to analyze the field correctly for the metric/imperial calculations?  I'm not sure how to accomplish this.  I'd like to learn how to do this, but I'm not sure it would work for this database, as I'm designing it for users who will be working very quickly, and I had split the FT and IN fields to ensure the calculation reads correctly if they forget to use the correct symbol (entering ' instead of " would render a false calculation, no?).

                     Ninja, for the stacked fields solution, I understand how this could control which field I'm entering data into, but how would it control which field is visible?  Would I have to make all of the fields transparent?  Say I enter data into the FT and IN fields, then switch modes to Metric.  Ideally I'd like that spot on the layout to show a field with the metric conversion of the FT/IN I already entered, and then still have that field editable....and then behind the scenes, if I swtiched back to Imperial Mode, the FT and IN would update when I change the data in the Meters field.

                     So far I haven't been able to figure out how to set up 2 way calculations.  example: edit Imperial field....Metric field calcs the conversion, then edit the metric field, and the imperial field updates.

                • 5. Re: Solution for Toggling between Imperial and Metric Units?
                  doronkipper

                       Aah, so I also just tried PhilModJunk's solution....unfortunetely I can't use tab controls for this switch because the fields exist in a portal.  The tab works on the first portal record, but does not show up on the others.  Any ideas?

                        

                  • 6. Re: Solution for Toggling between Imperial and Metric Units?
                    ninja

                         From your post, it looks like you want both fields on the layout (metric, imperial).  That's actually easier...

                         have an OnObjectSave trigger launch a script for each field...when Imperial is saved, calculate the metric and SetField the metric.

                         When metric is saved, calculate and Setfield the Imperial.

                         No stacking necessary.

                    • 7. Re: Solution for Toggling between Imperial and Metric Units?
                      JimMac

                           Sorry for slow response to a single field "interpretor" like FMP does on all calculations.  I will point you in a direction to experiment, since you have a lot of restrictions you want in your DB behavior.  The area of Power in FMP that is beneficial is TEXT FUNCTIONS.  As a beginner, I would suggest a script, although many programmers love the "one liner" calculation.  Scripting is easier to break down components of parsing and is easily extensible for future.

                           Lets focus on inches and feet and how "Friendly" you want program.  The single entry text field we will call Ht, for ease of my typingwink.  The first part is call "Standard Conditioning".  You want to adjust the text Field Ht, so that your Interpretor parses consistantly.

                           Example...

                           We are going to allow only the characters  quote [ ' ] and double quote [ " ]  and small [ m ] and point [ . ] and default of NO characters is meters.

                           Possible user entries in BOLD....

                      34.6   '  39           inches        34.6'39"

                      2 0 '                                           20'   

                      42                                              42m

                      5  cm                                         5m

                      16   .   45  m                              16.45m

                      5ft  10"                                         510"        hmmmm??

                      4.9meters                                 4.9m

                      7' 3m                                           Error  mixed units

                      crying  wow what did he mean? To "Standard Condition", use FMP Filter fuctions to remove all non allowed characters , like blanks and permit ,only [ [ 01234567889 " ' m ].  The Ht text field after Filter  and Substitute is shown italic.  You can allow different cases, it you wish.

                           Now you must Parse.... and interpret.  How did your mind just mentally flash the results?  Program that!yes.  I would "interpret " all to a consistant Decimal Meters result using Position function to find the Conditioned character  and use Left function to extract the number part.

                           From here just program the script to calculate and convert and put the result into the Standardized Height field.

                           Hope this points you....smiley

                           Jim...

                            

                      • 8. Re: Solution for Toggling between Imperial and Metric Units?
                        JimMac

                             I forgot my PS:angel  Plus i forgot the period [ . ] in the filter list.  Look at the Lower function to change M to m, in the conditioning step. 

                             PS:  See the mixed [ Errror ] and [ hmmmm?] ?  You can fix [ hmmm ]  that by allowing  feet and inches in words.  Simpley add [ i ] and [ f ] to the filter list and then Substitute [' for f] and [ " for i ]yes.

                             Who cares if you mix units?  Add the [m] number to meters and convert the Imperial numbers to meters and add to the Meters.wink

                             Jim...

                        • 9. Re: Solution for Toggling between Imperial and Metric Units?
                          doronkipper

                               Jim, I appreciate the explanation, I will experiment with that when I have a couple of hours to decipher it!  To be completely honest, I think my mind exploded while reading it.

                                

                               Ninja!  Thanks for the idea!  I did a test with an imperial and metric field side by side.....because both fields saving triggers the recalculation of the other, it seems to create a script loop where filemaker just freezes up trying to go between the two fields.  Any recommendation on how I can script it so that the other script won't trigger upon recalculation?

                          • 10. Re: Solution for Toggling between Imperial and Metric Units?
                            doronkipper

                                 I got the script triggers to work without a loop by setting an "exit script" depending on the Mode set in a global field ("Imperial" or "Metric Mode")

                                 Now!   To save space on the layout so that you only have to have one spot to enter the measurement, I tried the stacking trick Ninja mentioned (script trigger to go to field based on Imperial or Metric mode).  I stacked the FT (field) IN (field) layout over the M (field).....and set conditional formatting to make the IN. text black when in Imperial mode (it's natural state would be transparent so it goes away when Metric mode is engaged).....but as you can see in the attached screenshot, the text doesn't become truly transparent....it is just white.

                                 Screenshot below shows this:    

                                 1.me setting the text color to transparent

                                 2. the artifact the transparent "IN" creates on the Meters field data when I go to browse mode

                                 3. when I check the text color in layout mode again, it is WHITE now, it did not save my transparent selection...!!!????

                                  

                                  

                            • 11. Re: Solution for Toggling between Imperial and Metric Units?
                              JimMac

                              angel  You said "point" you in the direction.  Best advice is to read FMP help on text functions.  Try a few tests and you will see the  power.

                                   Take Care...

                                   Jim...

                              • 12. Re: Solution for Toggling between Imperial and Metric Units?
                                schamblee

                                     I made a sample that might work for you, I'm not %100 sure what you're looking for, but maybe it will get you in the right direction.

                                https://www.sugarsync.com/pf/D9559058_78149901_779748

                                • 13. Re: Solution for Toggling between Imperial and Metric Units?
                                  doronkipper

                                       Thanks S Chamblee.  I checked out the file.  I had not previously known about naming objects and scripting "go to object" to switch to a 0 width tab.  This is great!  Thanks!