Declaring Variables In Calculations And Scripts

From Dwayne Wright PMP, PMI-ACP, CSM
Certified FileMaker Developer

WEB: www.dwaynewright.com
EMAIL: info@dwaynewright.com
TWITTER: dwaynewright
YOUTUBE: FileMakerThoughts

Variables can be created and used in scripts and calculations. Variables are useful in simplifying complex calculations, passing information from one process to another and opening doors to innovation within FileMaker design.

I have seen mixed interpretations of declaring variables. I had it in mind that declaring a variable was the process of creating it. However, most resources I researched leaned more towards the use of a created variable and most of that was from a troubleshooting perspective.

So for the sake of conforming to a majority standard, I’m going to say that the term of a declared variable pertains to the use of an existing variable within a calculation or script.

When you create a variable, you give it a name. Just like when you create a field, you give that field a name. When you reference a field in a calculation, if that field name doesn’t exits, FileMaker tells you about it immediately. That is not true for variables when you use a variable in a script or calculation. Without the immediate feedback that a declared variable does not exist, the developer can introduce bugs within the FileMaker solution that are not easily tracked down.

Most variables in calculations are created, used and discarded within the same calculation. So depending on how intense a calculation is written, the developer can quickly see a typo in a declared variable.

Local script variables are also created, used and discarded within the same script process. This also is not to hard to troubleshoot, particularly for the FileMaker developer using the Script Debugger and Data Viewer that comes with FileMaker Advanced.

Global variables are created and used within the same FileMaker file but are not discarded until the users session ends. Depending on the organization and documentation of the developer, the use of a global variable can be dependent upon proper activation and declaration. If a global variable with the same name is created in multiple areas of a FileMaker solution, it could lead to problems on how they are used. The same is true if the global variable is set to different values in different areas of the FileMaker solution. For this reason, many developer shy away from using global variables.

Finally, there is one other technique of blending a calculation variable and a global variable that can greatly empower a FileMaker solution or cripple it. That is the use of creating a global variable within a Let function of a calculation. A variable created this way can be declared within calculations and scripts elsewhere. So if done properly and documented appropriately, creating a global variable within a calculation can be wonderful.

More info about the author and FileMaker in general, contact me at info@dwaynewright.com.

© 2010 - Dwayne Wright - dwaynewright.com