JavaScript Editor js editor     Web development 



Main Page

Defines global variables or arrays. There are two versions of the syntax.

PUBLIC MemVarList
PUBLIC [ ARRAY ] ArrayName1( nRows1 [ , nColumns1 ] ) [, ArrayName2( nRows2 [, nColumns2 ] ) ] ... 
   [AS type [OF ClassLib]]

Parameters

PUBLIC MemVarList


Specifies one or more memory variables to initialize and designate as global. Use commas to separate multiple items in MemVarList. The single letters A through J and M are reserved and cannot be used as variable names.
PUBLIC [ ARRAY ] ArrayName1( nRows1 [, nColumns1 ]В ) [, ArrayName2( nRows2 [, nColumns2]В )] ...


Specifies one or more arrays to initialize and designate as global. For more information about arrays, see DIMENSION Command.
[ AS type [OF ClassLib] ]


Specifies the data type of the variable or array and the class library containing the type description of type on which this variable or array is based. You can use the AS clause to implement strong typing. IntelliSense functionality is available for object and variable references only when they are strongly typed. For more information, see How to: Implement Strong Typing for Class, Object, and Variable Code.

Remarks

You can use and modify global variables and arrays from any program executed during the current Visual FoxPro session.

Variables and arrays created with PUBLIC are initialized to False (.F.) except for the public variables FOX and FOXPRO, which are initialized to True (.T.). Depending on the version of Visual FoxPro you are running, you can use the public variables FOX and FOXPRO to conditionally execute code.

Note:
The public variables FOX and FOXPRO were used in earlier versions to detect previous versions of FoxBASE and FoxPro, respectively.

You must declare any variables or arrays that you want public prior to assigning values to them. If you assign a value to a variable or array in a program and later declare it as public using PUBLIC, Visual FoxPro generates a syntax error.

Variables or arrays that you create from the Command window are automatically public.

Example

В Copy Code
SET TALK OFF
PUBLIC val1,val2
val1 = 10
val2 = 15

DO down
? val1
? val2

RELEASE ALL     && Releases private variables only
DISPLAY MEMORY LIKE val?
RELEASE val1,val2  && Public variables must be released explicitly
DISPLAY MEMORY LIKE val?

PROCEDURE down
PRIVATE val1
val1 = 50
val2 = 100
? val1
? val2
RETURN

See Also



JavaScript Editor js editor     Web development