Brian Dunning's FileMaker Custom Functions

fnSetGlobalVar ( Name ; Value )

Dynamically sets a global variable with a single script line.

  Average rating: 3.9 (54 votes) Log in to vote

Rob Poelking   Rob Poelking - Show more from this author
Excelisys, Inc.
http://excelisys.com

Share on Facebook Share on Twitter

  Sample input:
fnSetGlobalVar ( "myVar"; "myValue" )
  Sample output:
$$myVar = myValue

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Allows the user to set dynamic global vars without having to explicitly script a named variable. So you can have a single line script set variable [$var] pass the parameters and create a global var on the fly or destroy it by passing the name with no value. I needed to declare a global variable in a different file and did not want to script just for that single variable. I wanted something I could reuse as needed

 

Comments

Vaughan Bromfield   Vaughan Bromfield
Apr 23, 2010
Rob, I have taken the liberty to change the function to allow the repetition to also be specified. My changes also have it return the evaluation error code s the function result.

Many thanks for an excellent cf.

--- begin

// SetGlobalVar ( name ; repetition ; value )
// Author: Rob Poelking
// Date: 20080613
//
// Modified by Vaughan Bromfield to specify the repetition.
// The function returns the error result from the evaluationn operation
// which is zero when there is no error.
//
// This function does not check that the variable name is valid
// other than filtering out non-alphanumeric characters.

Let ( 

[
nameclean = Filter( name ; "ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz1234567890" ) ;
repetitionclean = Int( GetAsNumber( repetition ) )
] ; 

EvaluationError( Evaluate ( "Let ( $$" & nameclean & "[" & Max( repetitionclean ; 1 ) & "] = " & Quote ( Value )  & "; 0 )" ) )

) // end let


/* Notes: Allows the user to set dynamic global vars without having to explicitly script a named variable. So you can have a single line script set variable [$var] pass the parameters and create a global var on the fly or destroy it by passing the name with no value. I needed to declare a global variable in a different file and did not want to script just for that single variable. I wanted something I could reuse as needed. */

--- end
 
Rob Poelking   Rob Poelking, Excelisys, Inc.
Apr 23, 2010
Very good, I had actually done this myself already. I just hadn't updated this. However, I've started using a set of functions from Fabrice Nordmann for keeping a log of variables. VariablesLog, VariablesResetAll and LoadVariablesFromLog. They're very powerful and I highly recommend them.

Nevertheless, this is still a great function for what it does. Thanks.
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 15 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth:

Under construction. Email me your wish list for improvements.