9 Replies Latest reply on Jul 22, 2013 4:16 PM by philmodjunk

    How do you set a variable and then use it?

    ChrisJohnston

      Title

      How do you set a variable and then use it?

      Post


           I would like to know how to set a variable in a calcuation and then use it as what the calculation is. And then use it in other calculations. I have deduced a way to get the location of my FileMaker Database and want to use it again in other calculation fields. Once astablished as a global variable how do I tell the current field to use it? If any body can suggest a good starting place to learn more about these concepts as well would be good. Thanks

      variableHow.gif

        • 1. Re: How do you set a variable and then use it?
          philmodjunk

               Let ( $$fm = /* your calc for assigning a value to $$Fm goes here */  ; $$fm & //put rest of your calculation here)

               Note that this should be an unstored calculation. It won't work as a stored calculation nor as an auto-entered one.

               You can also use the set variable script step to set $$Fm to a value. Such a script can be set to run when the file is first opened to assign a value to it.

               Note that /* */ and // are comment operators that you would remove and replace with the expressions that you need.

          • 2. Re: How do you set a variable and then use it?
            ChrisJohnston

                 So my question is now I just tried it and I am still off, when I go into a another calculation field should I have access to $$fm?

            • 3. Re: How do you set a variable and then use it?
              philmodjunk

                   Yes, you should have access to the value of $$fm.

                   I recommend using a script to assign this value to the variable. It's less "hidden" than burying it inside a calculation like this and avoids issues with getting an existing calculation to re-evaluate in order to assign a value to the variable.

              • 4. Re: How do you set a variable and then use it?
                ChrisJohnston

                     Is this the way you would do it in a script? I seem to be doing something wrong. I don't have access to it when I do it in a script.

                • 5. Re: How do you set a variable and then use it?
                  philmodjunk

                       Please explain what you mean by "I don't have access to it".

                       The syntax you are using should successfully assign text to the variable, though it might not assign the file name with perfect accurracy as specifying 16 characters starting with the 7th character may or may not correctly reference the part of your file path that contains the file path to your file. If you move the file or put it inside additional folders, the length of your file path will change.

                  • 6. Re: How do you set a variable and then use it?
                    ChrisJohnston

                         What I mean by I don't have access to it is that when I go to a calculation and other things like merged fields it does not show up. For example I want the path I am generating to beable to concatenate with other fields and text. When I do that with the merged field i see the other text but not the path from my variable. Thanks for all the help by the way!

                    • 7. Re: How do you set a variable and then use it?
                      schamblee

                           You can use a calculation to generate the path, then you would not need a global variable. You have to run the script to set the variable, then you would have access to the variable. 

                           Insert your formula into a calculation field, then insert a merge field using this calculation field.

                      • 8. Re: How do you set a variable and then use it?
                        ChrisJohnston

                             Thanks! I kinda figured the you have to run it first part last night but was not sure. I am just about to finish my file maker trainging, and the last sections that I have not got ot yet covers script triggers. I my knowlege of program (not FileMaker yet) tell me there my be some way that FileMaker can trigger something to load all of the variables when the Database is opened. I understan that some varriables are not need untill the script that references them is in play. Is there any benifet to doing via a calculation rather that a script or vice versa? I was taking the advice given above and it seemed to make sence, that is defining variables in a script. When I used the same persons advice to use Let ( $$fm = /* your calc for assigning a value to $$Fm goes here */  ; $$fm & //put rest of your calculation here) It worke beautifully. I then took the advice put (try in my case) it in a script.

                        • 9. Re: How do you set a variable and then use it?
                          philmodjunk

                               See OnFirstWIndow open in File Options.