PUBLIC ARRAY Code Examples and SyntaxLast reviewed: August 11, 1997Article ID: Q121418 |
2.5x 2.60 2.60a | 2.00 2.5x 2.6 2.60a | 2.5x
WINDOWS | MS-DOS | MACINTOSHkbenv kbprg kbcode kbdocerr The information in this article applies to:
SUMMARYAlthough 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 INFORMATIONPlease 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 1The 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 2The 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 WINDOWThe 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. REFERENCESFoxPro 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" (c) Microsoft Corporation 1997, All Rights Reserved. Contributions by Perry Newton, Microsoft Corporation
|
Additional reference words: FoxMac FoxDos FoxWin 2.00 2.50 2.60 docerr
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |