adjustservervariable
DATABASE
,
VARIABLE
,
VALUE

The adjustservervariable statement adjusts the value of a server variable. This is an “atomic” operation, so it is multi-user friendly.


Parameters

This statement has three parameters:

database – name of the shared database that contains the server variable. 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 shared variable to be adjusted. The variable can be specified directly (not quoted), or with a formula.

value – the value to be used to change the server variable. If the server variable contains a numeric value, this parameter should be a number that will be added (or subtracted if negative) to the server variable value. If the server variable contains text, this value will be appended to the server variable.


Description

This function adjusts the value of a server variable. This is an “atomic” operation, so it is multi-user friendly (in other words, it will work correctly even if multiple users adjust the same value at the same time). If you need to increment or decrement a server variable, you should use this statement (or the adjustservervariable( function) instead of using the letservervariable statement and servervariable( function.

To illustrate this, suppose you want to keep track of how many times invoices have been printed to a PDF file – keeping track of the count no matter what computer was used to do the printing. This example shows how this can be done.

adjustservervariable "InvoicePrintCount",1
printtopdf "invoices.pdf","Form","Invoice Template"

Each time this code runs, the InvoicePrintCount server variable is incremented by one (1, 2, 3, 4, etc.). This calculation is done on the server and stored on the server, the new value isn’t even available on the local computer (if you want that value, you can use the adjustservervariable( function).

You might wonder why a special statement is needed for this. You might think – why can’t I just use the letservervariable statement and servervariable( function, and do the math with the + operator, something like this:

let count = servervariable("InvoicePrintCount")
letservervariable "InvoicePrintCount",count+1

This two step code will work fine when only one user is using the database. But if multiple people are using the database at the same time, there is always the chance that they will run this code at exactly the same time. Suppose the count is set to 2, and Bob and Frank both run this code at the exact same time. Both with get a count value of 2. Then both will add 1 and the new count will be 3. But that’s wrong, the count should be 4, since both Bob and Frank have printed.

By using the adjustservervariable statement, you make sure that each user get their own unique number (in this case one gets 3, the other 4), and that the final count is correct (in this case 4). Since the math is actually happening on the server, accesses is gated so that only one user can actually get access at a time. This is called an “atomic” operation because it can’t be split.

In addition to the adjustservervariable statement, there is also an adjustservervariable( function. This works just the same, however it also returns the new, updated value of the server variable to the local computer. If you don’t care what the new value is, the adjustservervariable statement is fine, but if you do need that value (for example to print it on your report), use the function version of this operation.

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

adjustservervariable «Base Tyre Size»,"25"

Normally the variable name is “hard coded” into the code as shown in the examples above, but you can also calculate the variable name with a formula instead. This example will create a different variable depending on the day of the week – MondayClose, TuesdayClose, WednesdayClose, etc. This example extends today’s closing time by 30 minutes.

adjustservervariable datepattern( today(),"DayOfWeek")+"Close",time("30")

The adjustservervariable 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.

adjustservervariable "Contacts",completedCallCount,1

See Also


History

VersionStatusNotes
10.2NewNew in this version.