6 Replies Latest reply on Jan 20, 2012 11:28 AM by Sprucegum

# Using a field value to set the operator in a calculation. Stuck!

### Title

Using a field value to set the operator in a calculation. Stuck!

### Post

Hi, I feel like this is going to be a stupid question to ask because it seems like it should be such a simple thing to do, but I admit, I am totally stuck! Here is the numeric calculation I am working on..

((Cost/Exchange rate) * (1+(Duty_new/100))) Landed Modifier Operator Landed Modifier

At the end of the caluclation are two seperate fields 'Landed Modifier Operator' and 'Landed Modifier'. The idea is that the user pics an operator  /,*,-,+ and this is the field value for 'Landed Modifier Operator'. They then enter any numeric value 'Landed Modifier' to apply, via the chosen operator, to the initial part of the calculation. The thing is FM wants to see operators between the initial calculation and the two fields, but I want 'Landed Modifier Operator' to be this operator and I cannot see how that's done?

Can anyone help?

Thanks, Matt.

• ###### 1. Re: Using a field value to set the operator in a calculation. Stuck!

Hi Matt,

I don’t think Filemaker allows values to be stored as ‘operators’, and so any value entered in Landed Modifier Operator is probably being stored as ‘text’.  Because there are a limited number of possible operators, you might try something like:

Let([

d = (Cost/Exchange rate) * (1+(Duty_new/100));

o = Landed Modifier Operator;

m = Landed Modifier];

Case(o = "/"; d / m; o = "*"; d * m; o = "+"; d + m; o = "-"; d - m; d)

)

• ###### 2. Re: Using a field value to set the operator in a calculation. Stuck!

Hey Sprucegum,

Perfect, works a treat! Although strangely FM doesn't seem to like the '-' in the value list and won't let it be selected. However that's no big deal as I can use the '+' operator and a negative numeric value to achieve the same thing.  I did try using Case, but this way makes more sense. Easy when you know how!

Many thanks,

Matt.

• ###### 3. Re: Using a field value to set the operator in a calculation. Stuck!

"FM doesn't seem to like the '-' in the value list and won't let it be selected"

You're right.  FM allows values in a value list to be separated using "-", (and so the separator cannot be selected as a value).  You could use underscore "_".

• ###### 4. Re: Using a field value to set the operator in a calculation. Stuck!

Yes, that's a thought. Thanks.

• ###### 5. Re: Using a field value to set the operator in a calculation. Stuck!

Actually, you can store operators in fields and then have a calculation use that operator to compute a value:

Use the evaluate function for that.

Evaluate ( (Cost/Exchange rate) * (1+(Duty_new/100)) & Landed Modifier Operator & Landed Modifier )

• ###### 6. Re: Using a field value to set the operator in a calculation. Stuck!

Hi Phil,

Very nice use of EVALUATE function.  Thanks very much for your invaluable contribution to this forum!