Easy Example Of The FileMaker Let Function
Friday, March 26, 2010 at 08:47PM From Dwayne Wright PMP
Certified FileMaker Developer
WEB: www.dwaynewright.com
EMAIL: info@dwaynewright.com
TWITTER: dwaynewright
YOUTUBE: FileMakerThoughts
The Let function can be challenging the first time you encounter it. Today I did a quick Let function to parse out the contents between a pair of parenthesis and realized this is a very easy way to explain how a Let function works!
Let([
$start = Position ( text ; "("; 1; 1)+1;
$end = Position ( text ; ")"; 1; 1);
$difference = $end - $start];
Middle ( text; $start; $difference)
The first variable we define tells us where the left parenthesis starts (plus one character), the second variable tells us were the right parenthesis ends and the last variables tells us the number of characters between each parenthesis. That sets up the last calculation that pulls out the desired data with the Middle function!
Reader Comments (3)
Dwayne, it would simplify your example if you used variables with no dollar sign. That way the variables only exist for the purposes of evaluating the calculation.
The $var form creates variables that persist while a script runs, which can be a useful technique, but is not everyday usage in a Let calculation.
I see your point but don't agree with your conclusion (at least in my design cadence). I tend to name my variables like this so I can easily identify them in the data viewer from traditional fields. I also have a habit of defining some $$ (global variables) in Let functions as a get away from multiple Set Variable script steps.
My variables are always distinguished by capitalization which can get sticky when doing custom software development, so thank you for the advice. I knew that there was a solution, but I was still struggling to figure one out exactly. SO thank you! :)