12 Replies Latest reply on Nov 4, 2014 10:29 AM by rickgraham_1

    I need help creating this custom function I found (please help!)

    rickgraham_1

      Title

      I need help creating this custom function I found (please help!)

      Post

      I want to create a script to convert weight measurements in recipes (layout) from US to metric or visa versa. I found this custom function with no instructions on how to implement it. It looks like it is correct but I can't figure out how to set it up. I'm very close, I have created a custom function before once but this one is  bit more difficult since it had absolutely no instructions with it. I get a message saying "the specified parameter can not be found" when I try to create a new function called "convert" and I paste this function in. can someone walk me through this? here is the web page with the custom formula (function) on it:

       

      http://www.briandunning.com/filemaker-custom-functions/detail.php?fn_id=246&function=rate&rating=4#comment_top

       

      ideally I'd like to make a button that runs a script to convert all the measurements in a recipe in a layout from US to metric or the other way around if that's possible. At the very least if you can help me to create the custom function called "convert" using this formula that would be very helpful. Then I guess I can fool around with it and figure out a way to use it in a script or do one field at a time in the layout or whatever. PLease help me, this formula looks very useful if you can help me to set it up I'm sure you will also like to have it for your own toolkit. It sure looks promising...

        • 1. Re: I need help creating this custom function I found (please help!)
          rickgraham_1

          Ok I am a little close now as I put in:

          Number
          From
          To

          and I get this error now: "A number, text constant, field name or “(” is expected here." instead of the previous error, so it looks like maybe the function formula has an error or is missing something? I wish the program would be more helpful about where "here" is, is the error in the little box with Number; From; To or the formula box? what's missing? I tried also adding "Fill" to the first little box after To but still get same error.

          • 2. Re: I need help creating this custom function I found (please help!)
            rickgraham_1

            this always happens to me, I go into a forum like this when I'm stumped. Then I start answering my own questions. Then I solve the thing before anyone ever gives a clue or answer. The formula is riddled with typo's. I am not a programmer, but I took logic in school. All of the commas are typo's which should be periods (.) once they are all corrected, the errors stop and I have created a new function. All that remains is to test it and figure out how to make a script that will convert all the numeric weight fields in the layout. I am now going to try that. meanwhile anyone wanting the corrected formula which I haven't tested yet but logic tells me is absolutely correct, well here it is submitted for your approval:

             

            /*  I use this function in recipes to convert the value of "number" "from" a unit measure "to" another . The function works with weight and capacity measure units: g. hg. kg. oz. fl.oz. gal. l. ml. cl. dl. cup. tsp. tbsp. lb and pint are recognized almost in any combination.
            Marco Terrile 2005 */

            Let ( [
            in = Lower(Filter( Trim (from); "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
            out = Lower(Filter( Trim (to); "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"));
            eq= in & out
            ];

            If(in = out; number;
            If( Left( eq;1) = "l";
            Case(
            eq = "lbg" ; number * 453.592427;
            eq = "lbhg" ; number * 4.53592427;
            eq = "lbkg" ; number * .453592427;
            eq = "lboz" ; number * 16;
            eq = "lbtsp" ; number * 96;
            eq = "lbtbsp" ; number * 32;
            eq = "lfloz" ; number * 33.814022201611;
            eq = "ldl"  ; number * 10;
            eq = "lcl" ; number * 100;
            eq = "lml" ; number * 1000;
            eq = "ltsp" ; number * 202.884119489;
            eq = "ltbsp" ; number * 67.628067271;
            eq = "lcup" ; number * 4.2267534898;
            eq = "lpint" ; number * 2.114164904863;
            eq = "lgal" ; number * .264172037284
            )
            ;
            Case(
            eq = "tbspg" ; number * 14;175;
            eq = "tbsphg" ; number * .15;
            eq = "tbspkg" ; number * .015;
            eq = "tbspoz" ; number * .5;
            eq = "tbsplb" ; number * .03125;
            eq = "tbsptsp" ; number * 3;
            eq = "tspg" ; number * 4.725;
            eq = "tsphg" ; number * .04725;
            eq = "tspkg" ; number * .004725;
            eq = "tspoz" ; number * .166666666667;
            eq = "tsplb" ; number * .010416666667;
            eq = "tsptbsp" ; number * .333333334;
            eq = "ozg" ; number * 28.35;
            eq = "ozhg" ; number * .2835;
            eq = "ozkg" ; number * .02835;
            eq = "ozlb" ; number * .0625;
            eq = "oztsp" ; number * 6;
            eq = "oztbsp" ; number * 2;
            eq = "kgg" ; number * 1000;
            eq = "kghg" ; number * 10;
            eq = "kgoz" ; number *  35.27336;
            eq = "kglb" ; number * 2.202643171806168;
            eq = "kgtsp" ; number * 211.64021164021;
            eq = "kgtbsp" ; number * 70.546737213404;
            eq = "hgg" ; number * 100;
            eq = "hgkg" ; number * .1;
            eq = "hgoz" ; number * 3.52733686067;
            eq = "hglb" ; number * .2202643171806168;
            eq = "hgtsp" ; number * 200;
            eq = "hgtbsp" ; number *  66.6666667;
            eq = "gkg" or eq = "mll" ; number * .001;
            eq = "goz" ; number * .0352;
            eq = "glb" ; number * .002202643171806168;
            eq = "gtsp" ; number * .21164021164;
            eq = "gtbsp" ; number * .070546737213;
            eq = "gall" ; number * 3.785412;
            eq = "galdl" ; number * 37.85412;
            eq = "galcl" ; number * 378.5412;
            eq = "galml" ; number * 3785.412;
            eq = "galcup" ; number * 16;
            eq = "galpint" ; number * 8;
            eq = "galfloz" ; number * 128;
            eq = "galtsp" ; number * 768;
            eq = "galtbsp" ; number * 256;
            eq = "tbspl" ; number * .01478676;
            eq = "tbspdl" ; number *  .1478676;
            eq = "tbspcl" ; number *  1.478676;
            eq = "tbspml" ; number * 14.78676;
            eq = "tbspcup" ; number * .0625;
            eq = "tbsppint" ; number * .03125;
            eq = "tbspfloz" ; number * .5;
            eq = "tbsptsp" ; number * 3;
            eq = "tbspgal" ; number * .00390625;
            eq = "tspl" ; number * .004928922;
            eq = "tspdl" ; number * .04928922;
            eq = "tspcl" ; number *  .4928922;
            eq = "tspml" ; number * 4.928922;
            eq = "tspcup" ; number * .020833333333;
            eq = "tsppint" ; number * .010416666667;
            eq = "tspfloz" ; number * .166666666667;
            eq = "tsptbsp" ; number * .333333333333;
            eq = "tspgal" ; number * .001302083366;
            eq = "flozl" ; number * .02957353;
            eq = "flozdl" ; number * .2957353;
            eq = "flozcl" ; number * 2.957353;
            eq = "flozml" ; number * 29.57353;
            eq = "flozcup" ; number * .125;
            eq = "flozpint" ; number * .0625;
            eq = "floztsp" ; number * 6;
            eq = "floztbsp" ; number * 2;
            eq = "flozgal" ; number * .0078125;
            eq = "pintl" ; number * .473;
            eq = "pintdl" ; number * 4.73;
            eq = "pintcl" ; number * 47.3;
            eq = "pintml" ; number * 473;
            eq = "pintcup" ; number * 2;
            eq = "pintfloz" ; number * 16;
            eq = "pinttsp" ; number * 96;
            eq = "pinttbsp" ; number * 32;
            eq = "pintgal" ; number * .125;
            eq = "cupl" ; number * .2365882;
            eq = "cupdl" ; number * 2.365882;
            eq = "cupcl" ; number * 23.65882;
            eq = "cupml" ; number * 236.5882;
            eq = "cuppint" ; number * .5;
            eq = "cupfloz" ; number * 8;
            eq = "cuptsp" ; number * 48;
            eq = "cuptbsp" ; number * 16;
            eq = "cupgal" ; number * .0625;
            eq = "mldl" or eq = "cll" or eq = "ghg" ; number * .01;
            eq = "mlcl" or eq = "cldl" or eq = "dll" ; number * .1;
            eq = "mlcup" ; number * .004237288136;
            eq = "mlpint" ; number * .002114164904862579;
            eq = "mlfloz" ; number * .033814022202;
            eq = "mltsp" ; number * .202884119489;
            eq = "mltbsp" ; number * .067628067271;
            eq = "mlgal" ; number * .000264172037;
            eq = "clcup" ; number * .042267534898;
            eq = "clpint" ; number * .021141649049;
            eq = "clfloz" ; number * .338140222016;
            eq = "cltsp" ; number * 2.02884119489;
            eq = "cltbsp" ; number * .67628067271;
            eq = "clgal" ; number * .002641720373;
            eq = "dlcl" or  eq = "clml" ; number * 10;
            eq = "dlml" ; number * 100;
            eq = "dlcup" ; number * .4237288136;
            eq = "dlpint" ; number * .2114164904863;
            eq = "dlfloz" ; number * 3.381402220161;
            eq = "dltsp" ; number * 20.2884119489;
            eq = "dltbsp" ; number * 6.7628067271;
            eq = "dlgal" ; number * .0264172037284
            )
            )
            )
            )

             

            so create a new function, then type in the three parameters                 number               from                    to              hit enter or plus sign after each one, then copy and paste my revised formula into lower box. Name it all convert (that's first step actually) and then save it with NO ERRORS!!! (thank you very much) DAMN I'm good!  I had no idea what I was doing and I didn't let that stop me... I'm very proud of myself! as usual the forum answers my problem, even though I'm the only poster in here.... thank you anyway. I will post the working script after I figure that one out!

            • 3. Re: I need help creating this custom function I found (please help!)
              rickgraham_1

              if anyone knows how to proceed, to use this formula in a layout and get it to output a conversion PLEASE SPEAK UP! once again I'm stumped from the example which says this:  Convert ( number ; from ; to )

              Sample Input:

                                                               
              Convert ( 12 ; "tbsp." ; "kg." )

              Sample Output:
              0,18

              PLEASE HELP! WHOEVER WROTE THIS PAGE SURE MADE IT VERY DIFFICULT FOR A ROOKIE TO GET A CLUE. I THINK FIXING THE FORMULA WAS THE HARD PART BUT IT'S STILL VERY DIFFICULT TO FIGURE OUT WHAT I SHOULD DO NEXT. OBVIOUSLY ONE FIELD FOR INPUT AND MAYBE ANOTHER CALCULATION FIELD FOR OUTPUT? who would convert tablespoons to kilograms anyway? I think Oz to Kg would make more sense which should also work with this function, or lbs to kg.

              • 4. Re: I need help creating this custom function I found (please help!)
                raybaudi

                Hi Rick

                yes, you'll need to have two fields.
                One ( number ) contains the number in tbsp, the other ( calculation ) will calculate the equivalent number in kg.
                The calculation fied use that custom function.

                Note also that from and to could be fields, instead of fixed strings, so to convert other type of measurments. In that case the fields must be four ( number, from, to and the calculation one ).

                BTW: that custom function was created by an Italian guy and there, as in other countries, the decimal separator is the comma.

                 

                • 5. Re: I need help creating this custom function I found (please help!)
                  rickgraham_1

                  Can you give example because I have tried many variations of that (the function appears to handle all conversions from US to metric such as LBs to KGs etc) but I can't get the function to do anything) also if you use the commas you can't even create the function at all due to errors and also he had commas and decimal points all through it which was really confusing. It only creates after all commas were  changed to decimal points. Can you get it to work? and can you give example of calculation needed? I'd like to be able to convert oz to kg and any other conversions needed in recipes. I don't think I need Tbsp to Kg that doesn't seem to be rational. Tbsp to Gr makes more sense. Oz to Gr also makes sense. Tbsp and Tsp I will probably leave alone in recipes. Just weight conversions I want.

                  • 6. Re: I need help creating this custom function I found (please help!)
                    raybaudi

                    Hi

                    post on dropbox ( or on other equivalent site ) your file, even if it is not functional.
                    I need it because my system works with commas as decimal separator.
                    I'll fix it so that it will work.

                    • 7. Re: I need help creating this custom function I found (please help!)
                      rickgraham_1

                      ok here's a dropbox link to recipes file. I have created the function convert. please can you make fields in edit recipes layout table and make it convert anything. I want grams to oz and visa versa, and cup, pint and quart, gallon to liter and visa versa but I guess if you can get it to dio just one I can figure out how to do the others... if you can do all then even better.

                      thanks for your time and effort in this important matter!

                      https://www.dropbox.com/s/70cbo3b3hfv02g7/recipes.fmp12?dl=0

                      • 9. Re: I need help creating this custom function I found (please help!)
                        rickgraham_1

                        I don't see any new fields or working calculation in here, please explain what you did.

                        • 10. Re: I need help creating this custom function I found (please help!)
                          rickgraham_1

                          looks like you just filled in the blanks with your own calculations, I need a working calculation that will do the math automatically converting to metric each regular entry. I put in the calculation but can't figure out how it is supposed to work. Please explain.

                          • 11. Re: I need help creating this custom function I found (please help!)
                            schamblee

                            I can't confirm that the conversion is correct, but it seem to work correctly.  You have to enter the qty and unit in US and then select the unit  in metric that you want computed then the qty is computed.  You have to fill in three fields to get the metric unit to compute.