7 Replies Latest reply on Jul 27, 2012 9:10 AM by philmodjunk

    Global Variables



      Global Variables


      I seem to have a global variable with a value left over from a previous report when it doesn't have a value in the current report.  What's the best way to make sure that doesn't happen?

        • 1. Re: Global Variables

          Two dollar signs in front of a variable makes it global.  One dollar sign is local.  Example $$Test is a global variable, $Test is a local.

          • 2. Re: Global Variables

            I understand that.  I need it to be a global variable because it is passed betwen scripts.  The problem is that is that when I run another report later that doesn't happen to use it (a CC email address), it still has the value from the previous report.  Should I just set it to a blank value " " at the beginning of each report script?


            • 3. Re: Global Variables

              Home > Reference > Script steps reference > Control script steps > Set Variable

              Set Variable
              Purpose   Sets a local or global variable to a specified value.
              Format    Set Variable [<variable name> {[<repetition number>]}; Value:<value or formula>]
              Click Specify to set the variable options:
              Name is the name of the variable you want to create. Prefix the name with $ for a local variable or $$ for a global variable. If no prefix is added, $ is automatically added to the beginning of the name.
              Value is the value the variable is set to. You can enter text or specify a calculation.
              Repetition is the repetition (index) number of the variable you want to create. If no repetition is specified, the default is 1.
              This script step is also supported in web publishing and in a FileMaker Server scheduled script.
              Originated in FileMaker Pro 6.0 or earlier
              If a variable doesn’t exist, this script step will create one. A variable name has the same naming restrictions as a field name. For more information, see About naming fields.

              Local and global variables can be created and used in calculations.
              A local variable can only be used in script steps in the currently executing script. The value in a local variable is cleared when the script exits.
              A global variable can be used in a calculation or script anywhere in a file, for example, other scripts or file paths. The value of a global variable is not cleared until the file is closed.
              Local and global variables (or even two local variables in different scripts) can have the same name but they are treated as different variables and can store different values.

              The following example sets a local variable.
              Set Variable [$commission; Value:.05]
              The following example sets a global variable.
              Set Variable [$$commission; Value:.1]
              • 4. Re: Global Variables

                It depends on your layout.  You could set it to blank.  You could delete the variable from that report that doesn't use it.  If this is a printout report you could also use "hide when printing" option in the inspector.

                • 5. Re: Global Variables

                  I should have been more specific.  I have a sub-routine that sends email by filling in the email address, CC email address, subject, and message from global variables that are set in the the script that calls the generic email script.  Some reports use the CC email, and some don't, but the global variable is in the sub-routine regardless.  If I don't set the global variable for the CC email, I need it to be blank rather than using the last value it held.


                  Would this work at the beginning of each report script:  Set Variable [$$TargetCC, Value: " "]  I just don't know the best way to reset it to a blank value.


                  • 6. Re: Global Variables

                    Yes that will blank $$TargetCC.   If the variable is displayed on the screen then you may need to refresh the window, to update the display.

                    • 7. Re: Global Variables

                      You also do not need the space between your quotes though doing so in this context appears harmless. You could use:

                      Set Variable [$$TargetCC, Value: ""]