Jump to content
Server Maintenance This Week. ×

vary operator with field


This topic is 7316 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies

I can't seem to do this, though it makes sense to me. I'm trying to set up a comparison like this:

fieldOne fieldOperatorChosen fieldTwo

where fieldOne and fieldTwo are values and fieldOperatorChosen is a value chosen from a value list with "=, ?, <, >" as options.

I know i can do it by branching off into different script versions, e.g. if fieldOperatorChosen="<" then perform script compareLessThan... and so forth.

But there has to be a better way. I've tried getField(fieldOperatorChosen) and getField("fieldOperatorChosen") but the validation never works.

I have a feeling I'm missing something obvious, at least I hope I am. confused.gif

FileMaker Version: Dev 7

Platform: Mac OS X Panther

Link to comment
Share on other sites

This looks like an ideal usage for the new Evaluate() calculation function!:

Evaluate( Quote(fieldOne) & fieldOperatorChosen & Quote(fieldTwo) )

The Quote() is needed to protect the contents of the field from the evaluate (imagine fieldOne containing the string 3+4, for instance).

I'm also not sure what you expect from ?, or is that just my browser futzing up the not= mark?

Link to comment
Share on other sites

  • Newbies

Disregard the following. I messed around with it and referenced a calculation field instead of the twice removed field in the original attempt. Thanks again.

Editted: Thought that worked but i was wrong. I don't think I know how to use this function. I'm putting it in a script to test like so:

If fieldOne & fieldOperatorChosen & fieldTwo

Set Field [matchFlag; "Match"]

where it means

If Yes = Yes

Then matchFlag="Match"

so i can do stuff later in the script...

I tried

If [Evaluate (Quote(fieldOne) & fieldOperatorChosen & Quote(fieldTwo))]

Set Field [matchFlag; "Match"]

But that's not actually working like i thought, it just happened to screw up correctly on the first test record, but actually returned that match for all records. I tried adding a test like

If [Evaluate (Quote(fieldOne) & fieldOperatorChosen & Quote(fieldTwo) "=1")] but no dice again. Is the evaluate function putting a value somewhere that I can test, there is scant little in the help or manuals about it?

Link to comment
Share on other sites

Well, I tried this out myself also, and have a sample file.

It seems the expression needs to have double Quote() calls:

Evaluate( Quote(Quote(fieldOne)) & compareWith & Quote(Quote(fieldTwo)) )

This struck me as odd, and I'll admit I'm not real clear yet on why one isn't enough.

The Evaluate() function takes a string and evaluates it as a calculation, exactly so you can do this sort of thing, for example:

Evaluate( "3 + 4" ) returns 7

and Evaluate( "3 " & comparesWith & " 4" )

returns the results of "3 < 4", "3 = 4", or "3 >= 4" depending on the value of comparesWith.

Hope this helps.

Link to comment
Share on other sites

Actually, a better way would be to delay the field expansion until the Evaluate():

Evaluate( "matchTest::fieldOne " & matchTest::compareWith & " matchTest::fieldTwo" )

where matchTest is the table containing these fields.

Then you shouldn't need any extra quoting at all. (but I haven't tried it).

Link to comment
Share on other sites

This topic is 7316 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.