Declares memory variables that are local in visibility but public in duration.

Syntax

STATIC <variable 1> [ = <value 1>] [,<variable 2> [ = <value>] ...]

<variable>

The variable to declare static.

<value>

The value to assign to the variable.

Description

Use STATIC to declare memory variables that are visible only to the routine where they’re declared but are not automatically cleared when the routine ends. Static variables are different from other scopes of memory variables in two important ways:

You can declare and assign a value to a static variable in a single statement, referred to as an in-line assignment.

Static variables initialized in a single statement are assigned the initialization value whenever the variable is undefined, including the first time the routine is executed and after the variable is cleared.

You must declare a variable STATIC before initializing it to a particular value. Declaring a variable STATIC without an in-line assignment creates it and initializes it to false. Once declared, a static variable will remain in memory until it is explicitly released (usually with CLEAR MEMORY).

Because static variables are not released when the routine in which they are created ends, you can use them to retain values for subsequent times that routine runs. To do this, use an in-line assignment. The first time dBASE Plus encounters the STATIC declaration, the variable is initialized to the in-line value. If the subroutine is run again, the variable is not reinitialized; instead, it retains whatever value it had when the routine last ended.

Because dBL is a dynamic object-oriented language, you usually assign new properties to an object to retain values between method calls. For example, if you’re calculating a running total in a report, you can create a property of the Report or Group object to store that number.

Static variables are only useful for truly generic functions that are not associated with objects, functions that might be called from different objects that need to share a persistent value, or for values that are maintained by a class—not each object. In this last case, the variables are referred to as static class variables.

For more information, see PUBLIC for a table that compares the scope of public, private, local, and static variables.