DOCUMENT:Q121418  10-NOV-1994  [FOXPRO]
TITLE   :INF: PUBLIC ARRAY Code Examples and Syntax
PRODUCT :Microsoft FoxPro
PROD/VER:2.5x 2.60 2.60a | 2.00 2.5x 2.6 2.60a | 2.5x
OPER/SYS:WINDOWS         | MS-DOS              | MACINTOSH
KEYWORDS: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.

REFERENCES
==========

FoxPro for MS-DOS "Commands & Functions," version 2.0, see "PUBLIC"

FoxPro for MS-DOS or Windows "Language Reference," version 2.5 or 2.6, page
L3-765

FoxPro for Macintosh "Language Reference," version 2.5b or 2.5c, page 613

FoxPro "Developer's Guide", Chapter 9, "Public and Private Arrays"

Additional reference words: FoxMac FoxDos FoxWin 2.00 2.50 2.60 docerr
KBCategory: kbprg kbcode kbdocerr
KBSubcategory:

=============================================================================

THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS
PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND.  MICROSOFT DISCLAIMS
ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  IN NO
EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR
ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL,
CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF
MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.  SOME STATES DO NOT ALLOW THE EXCLUSION
OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES
SO THE FOREGOING LIMITATION MAY NOT APPLY.

Copyright Microsoft Corporation 1994.