Microsoft KB Archive/121418

{| = PUBLIC ARRAY Code Examples and Syntax =
 * width="100%"|

ID: Q121418

2.5x 2.60 2.60a | 2.00 2.5x 2.6 2.60a | 2.5x

WINDOWS        | MS-DOS              | MACINTOSH kbenv kbprg kbcode kbdocerr The information in this article applies to:


 * Microsoft FoxPro for Windows, versions 2.5x, 2.6, 2.6a
 * Microsoft FoxPro for MS-DOS, versions 2.0, 2.5x, 2.6
 * Microsoft FoxPro for Macintosh, versions 2.5x

SUMMARY
Although there is no code or syntax example for the ARRAY clause of the PUBLIC command in the FoxPro 2.5 or 2.6 "Language Reference" manual or in the FoxPro 2.0 "Command & Functions" manual, there is a sample program that demonstrates the effect of PUBLIC versus PRIVATE arrays in the "Developer's Guide."

MORE INFORMATION
Please note that, as mentioned in the documentation, the PUBLIC command has no effect from the command line since all variables declared from the command line are PUBLIC by default; therefore, these code samples must be placed in a program file.

Example 1
The following example, which is printed in Chapter 9 of the FoxPro "Developer's Guide" under the topic of "Public and Private Arrays," creates and initializes a public array named MYARRAY:

SET TALK OFF CLEAR MEMORY CLEAR PUBLIC myarray(1,2)             && Create a public array. STORE 'main' TO myarray         && Store a value to the array.

? 'Main Program' DISPLAY MEMORY LIKE myarray    && Show the contents of the array. ?                              && Display a blank line.

DO this                        && Execute a lower-level procedure. ? 'Main program again' DISPLAY MEMORY LIKE myarray    && Contents of the array - no change! * end of main program

PROCEDURE this                 && Lower-level procedure. * Same array name as main. Declare it private. PRIVATE myarray DIMENSION myarray(1,1)         && Different size array. STORE 'this' TO myarray        && Store a value to the array.

? 'Lower-level procedure' DISPLAY MEMORY LIKE myarray    && Show the contents of both arrays. STORE 'this again' TO myarray ? 'Lower-level again'          && Change the array contents. DISPLAY MEMORY LIKE myarray    && Show the contents of both arrays. ?  RETURN                          && Return to the main program.

Example 2
The following code illustrates the syntax and results of the PUBLIC ARRAY command, which in this example both declares and initializes as a false (.F.) logical each element of a two-dimensional array named "ATESTARAY" having four elements:

PUBLIC ARRAY atestaray(2,2) DISPLAY MEMORY LIKE atestaray WAIT WINDOW The resulting display in the currently active window will look as follows: ATESTARAY  Pub    A     (   1,   1)     L  .F.     (   1,   2)     L  .F.     (   2,   1)     L  .F.     (   2,   2)     L  .F.