7 Replies Latest reply on Oct 21, 2013 2:47 PM by philmodjunk

    Having problems with a "Let" Calculation



      Having problems with a "Let" Calculation


           Im having a problem getting a "Let" calculation to run in a field

           I have 2 fields  from same table with the following calculations


           Case (FD::Set_By_Size = "No" ; Window::W_Width + B_Left + B_Right ;
                       FD::Set_By_Size = "Yes";Self


           Case (FD::Set_By_Size = "No" ; Window::W_Height + B_Left + B_Right ;
           FD::Set_By_Size = "Yes";Self

           the calculation uses   Window::W_Width   and   Window::W_Height   from a related table. when I change the values in this the 2 fields above behave properly

            But the "Let" Calculation wont run even though the fields are modifying.

           Any help?

        • 1. Re: Having problems with a "Let" Calculation

               I don't see any let function TO run. ??

               The use of self indicates that this is an auto-entered calculation.

               When an auto-entered calculation references fields in another table or record, it will not automatically update when you modify the value in the referenced field.

          • 2. Re: Having problems with a "Let" Calculation

                 The "Self" only works when  FD::Set_By_Size = "Yes" rarely used!


                 The LET calculation field in the same table as the CASE calculation fields

                 Case( Get ( RecordNumber ) = 1;

                      Let (
                      $W =( M_Width);
                      $H  =( M_Height);
                      $Mo = MBS("GMImage.New";$W & "x" & $H ;MFD::Swatch);
                      $Result = MBS("GMImage.WriteToPNGContainer"; $Mo);
                      $DestroyResult = MBS("GMImage.Destroy";$Mo)

                 Is there no way this will work?

            • 3. Re: Having problems with a "Let" Calculation

                   Now that I can see the Calculation we can take a look at why it does not work as expected. Is this an auto-entered calculation or the expression for a field of type calculation?

                   Your calculation references numerous local variables. They aren't global as they don't have two $$ at the beginning. I doubt that your calculation can work correctly as I don't think any of these variables will have a value at the time the calculation evaluates.

              • 4. Re: Having problems with a "Let" Calculation

                     Im not sure I understand!

                     The variables are created in the LET calculation.

                     The calculation itself works ok. it just doesnt fire when I modify (M_Width) (M_Height) which are from related table

                     As far as global variables are concerned I am trying to understand how they work.

                     If for example I set   $$ =( M_Width)  in this calculation will it then modify with field data changes?


                • 5. Re: Having problems with a "Let" Calculation

                       Sorry, my mistake on the variables, but since none of the values set are for a global fieldvariable, how do you know that it didn't since there is no visible change to see from it?

                            Let (
                            $$W = M_Width;

                       would assign the value of M_Width to the global variable $$W each time the Let function evaluates.

                       Is this a an auto-entered calculation or a calculation field?

                       PS. I'm not a big fan of using Let to assign values to a variable. It's a form of "side effect" programming that tends to hide where/when a variable got an assigned value. I much prefer to use a script in most cases.

                  • 6. Re: Having problems with a "Let" Calculation

                         Its a calculation field


                    • 7. Re: Having problems with a "Let" Calculation

                           Fixed a typo in my previous post.

                           Some developers put such an expression inside a conditional format expression on a layout in order to assign variable values.