Page 1 of 1
Evaluate text of field
Posted: Fri Aug 03, 2012 11:45 pm
by doobox
Hi there..
Stuck on a real simple one probably..
I have a field "test" contents of the field are for example "1+2=3"
I can do this:
Code: Select all
do field "test" as applescript
put the result into field "answer"
And i get the expected "true"
BUT..!
I'd rather not do things like that if i can help it.
So is there a way to convert the text of a field from a literal string, so it can be evaluated normally...?
Re: Evaluate text of field
Posted: Sat Aug 04, 2012 12:10 am
by sturgis
look at value()
with your example if you have 1 + 2 = 3 in field 1 then executing value(field 1) in the msg box returns true.
Changing it to 1 + 2 = 4 and then executing value(field 1) returns false as expected.
Re: Evaluate text of field
Posted: Sat Aug 04, 2012 12:22 am
by doobox
Perfect.. Thank you. That's the function a new must have existed.
I wonder how expensive it is.
I will be iterating in a repeat loop, and i need that answer real fast. We will see

Re: Evaluate text of field
Posted: Sat Aug 04, 2012 12:28 am
by sturgis
Don't use the field directly (for your list)
put the field contents into a variable and iterate through that.
If the list is REALLY long, use the "for each" form of repeat rather than "with i = 1 to..." form
Should be faster that way.
Re: Evaluate text of field
Posted: Sat Aug 04, 2012 12:32 am
by dunbarx
Hi.
What Sturgis said. Note that this works with text and lots of other expressions, like "a < b", 4 is an integer, "1/1/12 < 2/1/12".
All true.
And if you only had: "3 + 5", you would get "8".
Be careful, though. Try: "4 is a date"
Craig Newman
Re: Evaluate text of field
Posted: Sat Aug 04, 2012 12:40 am
by doobox
Thank's Craig...
Yep.. this can be real handy, when your sure you know what your evaluating.
Like you say though, it could quickly lead to unexpected bugs if one's not careful.
Try "4 is a char" that was pretty unexpected also

"Throws an ERROR..!"