Variables provide a temporary location for storing data, which can then be accessed from any context in the file. You can declare variables in:
•calculations using the Let function
•scripts using the following script steps: Set Variable, Get Directory, Show Custom Dialog, and the Insert script steps that let you specify a variable as the target
Variables are not available outside the file in which they are declared, and one user’s variables are not available to other users. If you need data to be available to other files or to multiple users, use a field (without global storage) instead of a variable.
When you declare a variable, you can specify its scope by adding a prefix before the variable name.
Scope | Prefix | Example | Availability |
Let function | None |
| Only within the Let function where it is declared |
local | $ |
| Only within the script where it is declared; cleared when the script ends |
global | $$ |
| Anywhere within the file where it is declared; cleared when 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.
You can use variables in:
•calculations
•scripts
•file paths (see Creating file paths)
•find requests that you create and edit in the Edit Find Request dialog box (see Specify Find Requests and Edit Find Request dialog boxes)
•layouts as merge variables (see Inserting merge variables onto a layout)
Variables can include an optional repetition number that appears in brackets [ ] immediately after the variable name. For example, the following returns 111:
Let ( [
$var[1] = 1;
$var[2] = 10;
$var[3] = 100
];
$var[1] + $var[2] + $var[3] )
Repetitions in variables are not supported in:
•merge variables
•file paths
•find requests
•A variable name has the same naming restrictions as a field name. See About naming fields.
•Variables are not supported in file paths that are stored in container fields.
•The data type of a variable is determined dynamically based on the assigned data. Variables have the same data types as fields, except for calculation and summary fields. See About choosing a field type.
•For more information on working with variables, see the FileMaker Knowledge Base.