Jump to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Evaluating local variables

Featured Replies

I'd like to pass a parameter to a custom function and return the local value for that parameter. I know that's a clunky way of saying what I mean. I want to code some values in a custom function return those values based on the parameter passed.

I want Eval ( "dog" ) to return "bark".

I tried this custom function:

Eval ( parameter )

Let( [

dog = "bark" ;

cat = "meow" ;

mouse = "squeak"

];

Evaluate ( parameter )

)

But that didn't work. I could use a Case () function but I expecting a lot of values in my list.

Thanks for any tips.

I could use a Case () function but I expecting a lot of values in my list.

Is using Let() any shorter? IIUC, you still need to define each input/output pair.

  • Author

Yes, you're right, it wouldn't be shorter. In fact, it the whole calc would evaluate faster, as not all the local variables would have to be evaluated. Once a true test is met, the Case() stops.

But now I realize there's something about Evaluate() I don't understand and I'd like to to learn why it doesn't work the way I think it should.

But now I realize there's something about Evaluate() I don't understand

I believe Evaluate() does not "look back" at the parameters defined by Let() or by a CF. So for example in:

Let ([

code = "message" 

] ;

Evaluate ( "code" )

)




the formula to be evaluated is code - and this produces Error#102 (Field is missing), because code is perceived as meaningless. OTOH, 




Let ([

$code = "message" 

] ;

Evaluate ( "$code" )

)

will return "message" as expected.

Or you could evaluate the whole thing:

Evaluate ( "Let ( [" & 

"dog = \"bark\" // etc.

& "] ;" & parameter & " )" )

Or you could evaluate the whole thing:

True, but then why would you?

I use a CF that is a modified version of that to parse name/value pairs when I pass multiple script parameters. What's your preferred method to pass multiple script parameters?

Yeah, OK - if they cannot be return-separated (my preferred method). Otherwise:

http://fmforums.com/forum/index.php?showtopic=39249&view=findpost&p=183000

However, with Set Variable[] I find the need for multi-valued parameter very rare.

Edited by comment

I've been burned too many times by return-separated variables:

1. you have to be careful about the order

2. unreliable for passing lists

I find the need for multi-value parameters very common. I often find myself coming back to a button that originally passed a single param and redefining it to pass name/value pairs.

What I like about the custom function method is that it takes so little thought when defining the parameter, e.g.:

"name=" & nameField &

"; id=" & IDfield &

"; ice cream=good" // etc

And then in my script:

Set Variable( $param ; Get( ScriptParameter ))

GetNamed( $param ; "id" ) // GetNamed being the name of the CF

  • Author

I recently started using SetProperty( name ; value ) and GetScriptProperty ( name ) for passing parameters between scripts and I'm really like it: http://www.goya.com.au/blog/using-name-value-pairs-parameters-and-storing-data

I don't think that relates to my question though.

The Evaluate() won't take a Let-defined variable as a valid expression is what tripped me up. It seems the answer is simply, "The computer says no."

Sorry if I derailed your thread, DJ. Michael asked why I would use Evaluate that way. (I still don't know why you're trying to use it the way you are.) B)

For any interested lurkers, I've posted the CF I use here:

http://fmforums.com/forum/topic/77148-passing-multiple-script-parameters/

Create an account or sign in to comment

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.