Jump to content

This topic is 3040 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Not sure if this is the right place in the forum to post this topic but it appears to be the closest to what what i think I want anyhoo:

I am just trying to discover and disect the Let Function. and have a "problem" I thought it might be useful in the following siuation but I am hust buggered as to where to start.

The problem for this example is;

I am working on a small POS for a friend they want the possiblity of having a voucher print if a certain amount of money is spent in 1 transaction.

So for the exercise i have set up a table (related it to Sales) to input 1 promotion that has an ID, Description, Barcode, Min Spend, and Active Status.

On the receipt i would like to print a barcode with the promo if the min spend (as dictated in the promo table) at sale is met.

I thought of a global field with a let function  and if the result is x then it should print to the receipt the details from the promo table( ie barcode description etc)but just dont know where to start apart from where i am at here

Let([
State=GetAsText(promotionStore::Active);
SalesTot = GetAsNumber (sales::total);
Min = GetAsNumber (PromotionStore::MinSpend)]);

for this purpose I am assuming that this would return the following if the promo was active, The total sale was $40 and the min spend was say $30

State=Active

SalesTot = 40

Min = 30

At this point I am assuming there should be a calc result but not sure what to do or where to put it or how to write it. (I know it may be blazingly simple but the old grey matter is just not computing this at present)

this explanation is probably clear as mud but hope that someone can help.

 

Link to comment
Share on other sites

10 minutes ago, Peter Barfield said:

Let([
State=GetAsText(promotionStore::Active);
SalesTot = GetAsNumber (sales::total);
Min = GetAsNumber (PromotionStore::MinSpend)]);

That's not valid syntax. The Let function has two parts: (a) the section where you define some variables, and (b) the section where you do the actual calculation that returns the result. You use the variables defined in the first section in the formula defined in the second section. Your calculation lacks the second section.

Note that the Let() function is used merely for convenience and for improving the performance (by calculating some interim results only once). There is nothing you cannot do without this function: just replace all variable references in the second section by their definitions in the first section.

Note also that defining a variable to equal a field is redundant: there is nothing to gain by referencing a variable instead of the field. In addition, Filemaker knows the field types, so you can dispense with the type casting.

I didn't really understand what you tried to accomplish in your exercise. It seems to me this is more a matter of relationships than calculations. 

 

 

Link to comment
Share on other sites

I understand completely what you are saying. As I said I am just coming to grips somewhat with this function and thought it might be a way of implementing it more for the "experience" of using it. I take on board what you have said though. I as yet have not found an example played out in simple laymans terms of using the function with real world examples although i will have to do more searching. I have watched Matt Petrowskys video but I was somewhat lost after a short while on that one. Syntax wise thats where i seem to just not get it for some obscure reason (normally i pick up on these things quickly) oh well i will keep trying. Cheers.

 

Link to comment
Share on other sites

14 minutes ago, Peter Barfield said:

I as yet have not found an example played out in simple laymans terms of using the function with real world examples

There are plenty of real-world examples right here. Here are a few I found very quickly:

 

 

 

Link to comment
Share on other sites

Thanks for that.Oddly it didnt even cross my mind to check the forum for examples in this case although it is something i normally always do. I guess i am just getting too consumed with this and not thinking clearly something i occasionally do when i get a bit into something that i am excited about. Will have to calm myself down and take a deep breath. (I guess i am just seeing the possibilities of this function and what it can do.) cheers

Link to comment
Share on other sites

In general, there's nothing that special about the Let function -- it just provides a way to make a calculation more readable (once you understand how to read it).

The exception to this is that it can also be used to create variables that persist outside the scope of the calculation, at either the script level ($var) or the file level ($$var). E.g.:

Let( $$displayWelcomeMergeText = "Hi, " & user::name ; "" )

The result of the calculation itself is empty. But the execution of the calc causes the variable to be created. Of course, you could simply use Set Variable to do that in a script, but the calculation above could be invoked in other places such as conditional formatting, etc.

Link to comment
Share on other sites

My view of the Let  function: While there are local variables ($) which endure as long as a script is running and global variables ($$) which persist as long as a file is open, the Let function declares variables that only persist for as long as the calculation takes. Other than that, nothing special but very valuable to be sure. It also makes calculations more readable and understandable as has already been mentioned.

Link to comment
Share on other sites

5 hours ago, Rick Whitelaw said:

While there are local variables ($) which endure as long as a script is running and global variables ($$) which persist as long as a file is open, the Let function declares variables that only persist for as long as the calculation takes.

Note that the Let() function can declare variables of all three types.

And the unprefixed variables are scoped only to the Let() function that declared them - not to the entire calculation.
See also: http://fmforums.com/topic/94863-how-can-i-use-the-let-function-to-set-a-localvariable/#comment-434255

Edited by comment
Link to comment
Share on other sites

This topic is 3040 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.