Variables provide a temporary location for storing data, which can then be accessed from any context in the file. You can define variables in:
•calculations using the Let and While functions
•scripts using script steps such as Set Variable, Get Folder Path, Show Custom Dialog, Read from Data File, and certain Insert script steps
Variables are not available outside the file in which they are defined, 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 define a variable, you can specify its scope by adding a prefix before the variable name.
Scope | Prefix | Example | Availability |
function | None |
| Only within the function where it is defined |
local | $ |
| Only within the script where it is defined (not available to sub-scripts); cleared when the script ends |
global | $$ |
| Anywhere within the file where it is defined; 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)
Local and global 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
•Variable names must follow the same naming restrictions as field names. 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.