Declares global memory variables.

Syntax

PUBLIC <memvar list>

<memvar list>

The memory variables to make public.

Description

A variable’s scope is determined by two factors: its duration and its visibility. A variable’s duration determines when the variable will be destroyed, and its visibility determines in which routines the variable can be seen.

Use PUBLIC to declare a memory variable that has an indefinite duration and is available to all routines and to the Command window.

You must declare a variable PUBLIC before initializing it to a particular value. Declaring a variable PUBLIC creates it and initializes it to false. Once declared, a public variable will remain in memory until it is explicitly released.

By default, variables you initialize in the Command window are public, and those you initialize in programs without a scope declaration are private. (Variables initialized in the Command window when a program is suspended are private to that program.) The following table compares the characteristics of variables declared PUBLIC, PRIVATE, LOCAL and STATIC in a routine called CreateVar.

 

PUBLIC

PRIVATE

LOCAL

STATIC

Created when it is declared and initialized to a value of false

Y

N

Y

Can be used and changed in CreateVar

Y

Y

Y

Y

Can be used and changed in lower-level routines called by CreateVar

Y

Y

N

N

Can be used and changed in higher-level routines that call CreateVar

Y

N

N

N

Automatically released when CreateVar ends

N

Y

Y

N

Public variables are rarely used in programs. To maintain global values, it’s better to create properties of the _app object. As properties, they will not conflict with variables that you might have with the same name, and they can communicate with each other more easily.