Hi this is Michelle at AppWorks. Today I’m going to show you how to use a let function. We’ll start by opening out data viewer and beginning a new expression. The let function is a little different than most other functions that you’ll come across in FileMaker. Rather than try to explain it, I will show you how it works.

We’re going to first add in some brackets so that we can add in multiple expressions before eventually outputting a calculation. Now an expression is very similar to creating a variable, so if I were to say, date = get(CurrentDate), and then output date in our calculation section, you’d see that we get the current date. The nice thing about this is that I can change what’s up here in our expression, and have it automatically update down here. This probably doesn’t seem very useful right now – we could’ve just put get(CurrentDate) + 1 down here, but in a long, complex calculation, a let statement can really come in handy to substantiate a lot of variables, help you shorten your code in your actual calculation, and generally make for more readable code.

Now that we’ve created our first one, let’s go ahead and keep going. If we output next week instead, now we have next week. Another use of a let function is to create actual variables that can be used during a script. If we say, let $date = get(CurrentDate), then when we hit Monitor, this variable will actually be created. Now, we’re in the process of a script, so we won’t stay, but if we were running the script, then this variable would then become available to the entire script. If we add two $$, making this a global variable, and we say Monitor, we’re going to find this new global variable here on our current tab. That’s just one more use of the Let Function.

So now we know that we can output the result of one of our expressions. Let’s go ahead and actually use this in a calculation. So we will do a case statement, and we will check to make sure that GET(CurrentDate) = $$date. If so, we will output a result of 1 for true. Otherwise, we will say false. As you can see, we instantly get our result of 1, and our calculation marks correctly. Thanks for watching.