Database Reference
In-Depth Information
Let ( AmountDue = Sum ( Line Items::Extended Price ) ;
If (
Get(CurrentDate) > Date Due and AmountDue > 0;
AmountDue + ( AmountDue * .05 );
AmountDue
)
)
This version of the calculation is simpler, easier to change, and more efficient when it evalu-
ates. You can't beat that.
The Life of a Variable
Most variables last only as long as it takes FileMaker to work through the calculation and
then they're gone. These variables are called local variables because they aren't valid out-
side the Let() function that calls them into existence. But you can also create a special vari-
able called a global variable , which lives beyond your calculation. Read on to see when to
use each type.
Local Variables
The variables you've written so far have all been local variables. Now it's time to learn that
local variables have shockingly short memories.
Local variables can lose their values even before a calculation is finished. If you write:
Let ( AmountDue = Sum ( Line Items::Extended Price ) ;
If (
Get(CurrentDate) > Date Due and AmountDue > Total Paid;
AmountDue + ( AmountDue * .05 );
AmountDue
)
) & If ( AmountDue < 0 ; "CR" ; "" )
the calculation tries to use the AmountDue variable after the end parenthesis in the Let()
function (that's the first one in the calculation's last line). Anything that happens after that in
the calculation is outside the Let() function's scope (a technical term that refers to when the
variable exists), so when you try to close the Specify Calculation window on this calculation,
FileMaker complains that it doesn't know what that last AmountDue is supposed to be. Here's
one way to rewrite that calculation by using a local variable:
Let ( AmountDue = Sum ( Line Items::Extended Price ) ;
Case (
Get ( CurrentDate ) > Date Due and AmountDue > Total Paid;
AmountDue + ( AmountDue * .05 ) ;
Search WWH ::




Custom Search