assignservervariable
DATABASE
,
VARIABLE
,
VALUE

The assignservervariable statement assigns a value to a permanent variable on the server. If the server variable does not already exist, it will be created.


Parameters

This statement has three parameters:

database – name of the database. This must be a shared database that is currently open. If this parameter is omitted or is empty, the current database is assumed.

variable – name of the variable. The variable can be specified directly (not quoted), or with a formula.

value – new value to be assigned to the variable. Any type of value is allowed: text, numeric, date, even binary values like dictionaries.


Description

This statement assigns a value to a permanent variable on the server. The variable will belong to a shared database (usually the current database, but any open shared database can be specified). If the server variable does not already exist, it will be created.

This example assigns the value 714 to the shared variable defaultAreaCode.

assignservervariable defaultAreaCode,"714"

Later, the value could be modified by using the assignservervariable statement again.

assignservervariable defaultAreaCode,"909"

To access this variable, use the servervariable( function, as shown in the example below. This variable can be accessed from any computer that has the shared file that contains the variable open.

servervariable("defaultAreaCode") ☞ 909

If the variable name contains spaces or other punctuation, you must surround the variable name with chevrons (Option-\ and Shift-Option-), like this:

assignservervariable «Default Area Code»,"415"

Normally the variable name is “hard coded” into the code as shown in the example above, but you also have the option of calculating the variable name with a formula. This example will create a different variable depending on the day of the week – MondayClose, TuesdayClose, WednesdayClose, etc.

assignservervariable datepattern( today(),"DayOfWeek")+"Close",time("8pm")

The assignservervariable statement normally modifies a server variable belonging to the current database, but you can specify a different database if you want. The specified database must be a shared database, and it must be currently open. Here is a revised version of the previous example that modifies the server defaultAreaCode variable in the Contacts database instead of the current database.

assignservervariable "Contacts",defaultAreaCode,"213"

Note: Another way to assign a value to a server variable is to use the letservervariable statement, like this:

letservervariable defaultAreaCode = 714

As you can see, the letservervariable statement uses an equals sign instead of a comma. Otherwise it is identical to the assignservervariable function (however, the letservervariable statement does not let you specify an alternate database, or specify the variable name with a formula instead of hard coding it).

IMPORTANT: If you want to modify a shared value by incrementing, decrementing or appending to it, use the adjustservervariable statement or the adjustservervariable( function. These operations are designed to correctly modify a shared value in a multi-user environment, so that the correct value is generated even if two or more users on different computers modify the value at the same time.


See Also


History

VersionStatusNotes
10.2NewNew in this version.