### Variable scopes for Crystal syntax

Declaring a scope for your variable regulates its availability through different parts of your report. See Variable Scope (Crystal syntax).

The variable scopes available are:

- Global
  The variable is available to formulas throughout the entire current report.
- Shared
  The variable can be shared with a subreport as well as the entire current report.
- Local
  The variable is specific and can only be used in the formula in which it is defined.

To use variable scopes you add the scope that you want to declare with your variable at the beginning of your variable declaration statement. You can also omit the scope keyword and start the variable declaration with the type name. This is the same as declaring a Global variable.

##### Examples

`NumberVar Amount;`

Declares a global variable named Amount that can hold any value of an integer or decimal data type.

`Global NumberVar Amount;`

Declares a global variable named Amount that can hold any value of an integer or decimal data type. This variable would be available to formulas throughout the current report

`BooleanVar Outstanding;`

Declares a global variable named Outstanding that can hold a TRUE or FALSE value.

`Shared BooleanVar Outstanding;`

Declares a shared variable named Outstanding that can hold a TRUE or FALSE value. This variable would be available in both the main report and any subreports contained within the main report.

`StringVar LastName := "Adams";`

Declares a global variable named LastName that can hold a string value and assigns the string "Adams" to that variable.

`Local StringVar LastName : = "Adams";`

Declares a local variable named LastName that can hold a string value and assigns the string "Adams" to that variable. This variable would be available only within the formula which it was declared.

##### Comments

- Your variable declaration statement is used to set aside a block of memory to hold the value assigned to the variable, and to assign a default value to that memory block. The default value assigned depends on the data type stored by the particular variable declarator used and on whether or not a value was assigned when the variable was declared.
- A variable declared in two formulas uses the same block of memory (that is, it refers to the same value.) For example:

//Formula #1
NumberVar x;
x:=5

//Formula #2
NumberVar x;
x:=x+15

x now has the value of 20.

###### Related topics

Variable declarations (Crystal syntax).

Seagate Software, Inc. http://www.seagatesoftware.com Please send comments to: techpubs@seagatesoftware.com