Goodies 12: Check variables

If enabled, MBS Plugin can check variable usage in a script. This requires a style where you declare all variables before you use them. For most script steps defining variables, we do detect those automatically. But it may be needed, that you use Set Variable on the beginning of the script to fill all variables you need later with empty values.

For variables defined in Let statements or new script statements we do not recognize, you can use comment lines with @variable, @constant or @parameter on the beginning followed by the variable name. This will be recognized as a valid definition of the variable.

Please avoid spaces in variables as we only check the name before the first space.

If a variable is not found, we show the message in the Script Workspace in red on the right side of the script window. We can show a notification to you, if you enable notifications for FileMaker in system preferences. You don't need to click away the notifications for missing variables as they will auto disappear after a few seconds.

Checking for Let statements

As you may know we have a variable check for FileMaker Script Workspace for macOS in MBS FileMaker Plugin. This works fine for most scripts, but you may need to know a few pitfalls. Since the plugin reads what is in the Script Workspace window and FileMaker truncates long lines, it will not catch a variable mistyped in a very long line. When we read a calculation like this one:



// define some variables

$varDefined = 1; $secondVarDefined = 2]; $varDefined) 


The plugin sees it as


Let([ // define some variables $varDefined = 1; $secondVarDefined = 2]; $varDefined) 


We don't get line breaks, so we have no idea where the comment ends and thus we can't find mistyped variable there.


There has been a problem that not scanning Let() for variable definitions, we now allow you to add a comment in front of the Let() or custom function call to define the variables: Start with a // comment and add they keywords @variable, @parameter or @constant (or shorter @var, @param or @const), then add a new line and continue with the calculation.

comment and add they keywords @variable, @parameter or @constant (or shorter @var, @param or @const), then add a new line and continue with the calculation.



// @var $varDefined, $secondVarDefined


// define some variables

$varDefined = 1; $secondVarDefined = 2]; $varDefined)


The plugin will recognize the comment and accept the variable even as we can't parse the Let statement due to missing line breaks.


Here is a test script showing various checking situations.


# you define a variable regularly

Set Variable [ $var1 ; Value: 1 ] 

# and use it

Set Variable [ $var2 ; Value: $var1 + 1 ] 

# now we define one via comment in Let()

Set Variable [ $test ; Value: 

// @var $varDefined, $secondVarDefined


// define some variables

$varDefined = 1; $secondVarDefined = 2]; $varDefined)

# or here in a comment line to define a variable set by custom function:

# @var $thirdVarDefined

Set Variable [ $test ; Value: SomeCustomFunction ] 

# or now with comment inline:

Set Variable [ $test ; Value: 

// @var $thirdVarDefined


# and use them

Set Variable [ $r ; Value: $varDefined + $secondVarDefined + $thirdVarDefined ] 

# If you don't declare it, we may catch it as an error:

Set Variable [ $test ; Value: Let([$NotDefined = 1]; 1) ] 

Set Variable [ $test ; Value: $testing + 1 ] 

# and this includes using an accent, which gives a different name:

Set Variable [ $test ; Value: $varDefíned + 1 ] 


Available in version 13.5 or newer on macOS.


To improve performance we disable checking while scrolling. We scan for up to 500 lines up to find variables. This limit can be adjusted with SyntaxColoring.CheckVariableDeclaration.SetLimits function. By default we disable the feature for scripts over 2000 lines to avoid the Script Workspace slow down too much.

Remember column widths 12 Sort contextual menu