1 Reply Latest reply on Jan 7, 2013 2:20 PM by philmodjunk

    How and when to use $Variable



      How and when to use $Variable


           I am going after Filemaker videos or manual where i can learn about when and how to use local or global Variable. is the any easyest way to undestand it?

        • 1. Re: How and when to use $Variable

               Keep track of what's different and what works with your version of FileMaker.

               $Variable--a local variable which, if created within a script can store a variable that is only accessible from other script steps within that script and it retains a value only as long as the script is executing. If script 1 assigns a value to variable $X and script 2 assigns a variable to $X, these are two different variables even though the names are the same.

               $$Variable--this is a "global" variable. A value assigned to it is accessible from any layout and any script in your file. If two scripts modify the value of $$X they are modifying the value of the same variable. The value in the variable will be retained until you close the file.

               There are two ways to create either type of variable:

               Set Variable in a script can assign a value to a variable. and the Let function can assign a value to a variable such as Let ( $X = 5 + NumberField ; ). The interesting part about the Let function is that this let function can be inside a calculation field, a script step, a conditional format expression or a custom funciton. This is a kind of "side effect" programming that can bury the code that assigned a value to a global variable in a difficult to locate place, but it has it's uses such as assigning a value to a variable via a conditional format expression such that you get the equivalent of defineing an unstored calculation field without actually adding a field definition to a table.

               There's even a third type of variable though it isn't always recognized as such, Variable (no dollar sign) as you might see inside a let function:

               Let ( X = 5 + 2 ; ...

               Such a variable only exists within the enclosing parenthesis of that one let function.