4 Replies Latest reply on Jan 28, 2013 9:50 AM by philmodjunk

    Saving global variables



      Saving global variables


           Is there a way to store the values of certain global variables that I want to be reassigned at startup with the same values they had the last time I closed the file?  I would prefer something where I can just enter the names of my variables in something like a single global field -- or some other way that I can easily modify my list and have a shut down & startup script parse the field, but I'm at a loss of where to even begin with parsing.

        • 1. Re: Saving global variables

               Try creating a new table that will have just one record, which include all the "globals" from last closed file.  On start up, that new table single record is your global values.


               Create one record per global and loop thru them.


          • 2. Re: Saving global variables

                 Thank you for the suggestions!

                 I hoped it could be done with one record and two global fields.  I'd like to enter all the $$variable names I want to retain (or delete them when I don't want them anymore) in one global field -- one $$variable name per line -- and have the other global field for my shutdown script to write each of those variables' values on corresponding lines.  I don't know if this is technically possible.  It doesn't look like there's a way to assign a variable name in scripts other than with the "set variable" step, and it doesn't seem to have an option to "get" a variable name.  So I probably can't set a variable's name to the value of line x of field 1 and then set that variable's value to line x of field 2.

                 I may need to drop this idea and move on to more productive work on my file.  

                 Thank you again.

            • 3. Re: Saving global variables

                   $$Name is just one way to make a global variable.  Before FMP added them to their program we did what i suggested and the names were constant.  Many used names like  gName  to represent a global variable.  With my suggestion, using gName  shows in your list for easy of scripting versus $$Name. And for lists check out the functions that make working Lists easy.


              • 4. Re: Saving global variables

                     If this database is not hosted over a network--you just have a single file option, you can use global fields instead of global variables and your data is automatically stored. If your database is hosted over a network, use Jim's method. Many hosted databases use a script set to run when the file is opened by a client that copies the saved values from such a table into the global fields.

                     You can then set up a script that runs when the file is closed to copy the global field values back to this table, but keep in mind that with multiple users, the last user to save overwrites previous values unless  you take additional steps to preserve a different set of values in this table for each user.