September 15, 200322 yr Hi I am having trouble with the following. I want to have an equation in a global text field which the user can edit if they wish. I then need to insert this global text field (which has fieldnames in the formula) into a Calculation field. When I try to do this, all I see is the formula text show up in the Calculation field. Is there a special way I need to insert this? Basically here is what I'm doing. I have a global text field called gCalc. In the Calculation field (called Calc), I have Calc=gCalc. This is not working as I described above, so I am obviously doing something wrong. I'm pretty new to all this, so any help would be appreciated.
September 15, 200322 yr Are they the same type of field? When you created the Global field, there was an option dialog box that openned that allows you to select the field type. To check this, select the field in Define Fields, and the Select the Options Button. This will give you the Dialog box again, verify that the two fields are of the same type. HTH Lee LEe
September 15, 200322 yr What you are trying to do is not possible in Filemaker. The formula in a calculation field is part of the database structure and Filemaker doesn't have functions or script steps to edit it. SetField[] set the field's content not its definition, so it fails when trying to edit a calculation field, because the content is defined by the formula.
September 15, 200322 yr What you are after would require a very complex calculation.... Here's a very little Example : Field1(num) Field2 (num) Field3 (num) Formula (Text) Use "A" for Addition, "D" for Division, "M" for Multiply and "S" for substraction, so that your formula looks something like "Field1 M Field2 P Field 3". AFAK, the definitive calc could be as long as : Case(Rightwords(Leftwords(Formula, 4), 1) = "A",Case(Rightwords(Leftwords(Formula, 2), 1) = "A",GetField(Rightwords(Leftwords(Formula, 1), 1)) + GetField(Rightwords(Leftwords(Formula, 3), 1)),Rightwords(Leftwords(Formula, 2), 1) = "M",GetField(Rightwords(Leftwords(Formula, 1), 1)) * GetField(Rightwords(Leftwords(Formula, 3), 1)),Rightwords(Leftwords(Formula, 2), 1) = "D",GetField(Rightwords(Leftwords(Formula, 1), 1)) / GetField(Rightwords(Leftwords(Formula, 3), 1)),Rightwords(Leftwords(Formula, 2), 1) = "S",GetField(Rightwords(Leftwords(Formula, 1), 1)) - GetField(Rightwords(Leftwords(Formula, 3), 1))) + GetField(Rightwords(Leftwords(Formula, 5), 1)), Rightwords(Leftwords(Formula, 4), 1) = "M",Case(Rightwords(Leftwords(Formula, 2), 1) = "A",GetField(Rightwords(Leftwords(Formula, 1), 1)) + GetField(Rightwords(Leftwords(Formula, 3), 1)),Rightwords(Leftwords(Formula, 2), 1) = "M",GetField(Rightwords(Leftwords(Formula, 1), 1)) * GetField(Rightwords(Leftwords(Formula, 3), 1)),Rightwords(Leftwords(Formula, 2), 1) = "D",GetField(Rightwords(Leftwords(Formula, 1), 1)) / GetField(Rightwords(Leftwords(Formula, 3), 1)),Rightwords(Leftwords(Formula, 2), 1) = "S",GetField(Rightwords(Leftwords(Formula, 1), 1)) - GetField(Rightwords(Leftwords(Formula, 3), 1))) * GetField(Rightwords(Leftwords(Formula, 5), 1)), Rightwords(Leftwords(Formula, 4), 1) = "D",Case(Rightwords(Leftwords(Formula, 2), 1) = "A",GetField(Rightwords(Leftwords(Formula, 1), 1)) + GetField(Rightwords(Leftwords(Formula, 3), 1)),Rightwords(Leftwords(Formula, 2), 1) = "M",GetField(Rightwords(Leftwords(Formula, 1), 1)) * GetField(Rightwords(Leftwords(Formula, 3), 1)),Rightwords(Leftwords(Formula, 2), 1) = "D",GetField(Rightwords(Leftwords(Formula, 1), 1)) / GetField(Rightwords(Leftwords(Formula, 3), 1)),Rightwords(Leftwords(Formula, 2), 1) = "S",GetField(Rightwords(Leftwords(Formula, 1), 1)) - GetField(Rightwords(Leftwords(Formula, 3), 1))) / GetField(Rightwords(Leftwords(Formula, 5), 1)), Rightwords(Leftwords(Formula, 4), 1) = "S",Case(Rightwords(Leftwords(Formula, 2), 1) = "A",GetField(Rightwords(Leftwords(Formula, 1), 1)) + GetField(Rightwords(Leftwords(Formula, 3), 1)),Rightwords(Leftwords(Formula, 2), 1) = "M",GetField(Rightwords(Leftwords(Formula, 1), 1)) * GetField(Rightwords(Leftwords(Formula, 3), 1)),Rightwords(Leftwords(Formula, 2), 1) = "D",GetField(Rightwords(Leftwords(Formula, 1), 1)) / GetField(Rightwords(Leftwords(Formula, 3), 1)),Rightwords(Leftwords(Formula, 2), 1) = "S",GetField(Rightwords(Leftwords(Formula, 1), 1)) - GetField(Rightwords(Leftwords(Formula, 3), 1))) - GetField(Rightwords(Leftwords(Formula, 5), 1))) Changing the separators would alter the calc. If you want to go that way, good luck !0
September 15, 200322 yr Author Ouch!, I didn't realize it would be such a pain. Thanks for all the help.
September 15, 200322 yr Until FM makes an Eval() function available, Ugo probably has the best and (unfortunately) most efficient idea for such a calculation.
September 16, 200322 yr It could probably be done a bit more simply using a script to parse the equation, but it would still be complicated.
Create an account or sign in to comment