Local, Private, Public
These three commands let you specify the scope of variables. FoxPro has had PRIVATE and PUBLIC for a long time, but LOCAL was added in Visual FoxPro. In the words of an ad, this changes everything. Visual FoxPro 7 adds other features we've been looking for: early binding and strong typing. So what's the big deal about early binding? We can define a variable as a class, and, during development, IntelliSense reads the type library and displays properties and methods. Cool. Way cool.
Usage |
LOCAL [ ARRAY ] Variable1 [ AS cType [ OF cClassLib ] ] ; [ , Variable2 [ , ... ] ] PUBLIC [ ARRAY ] Variable1 [ AS cType [ OF cClassLib ] ] ; [ , Variable2 [ , ... ] ] PRIVATE Variable1 [ , Variable2 [ , ... ] ] PRIVATE ALL [ LIKE FileSkel | EXCEPT FileSkel ] |
Parameter |
Value |
Meaning |
cType |
Character |
The data type. This can be a FoxPro data type, such as String, Double, or Logical. It can also be any VFP base class, such as Form or Spinner. You can also pass your own class, in which case you should use the cClassLib parameter so VFP can find your class. (You can register your classes with the IntelliSense manager; then you don't need to include cClassLib.) You may also use any class name found in the Registry, such as "Excel.Application" or "Word.Application". |
cClassLib |
Character |
If cType is a class name defined in a class library, the name of the class library. |
Example |
PUBLIC cUserName && But don't really do this PRIVATE ALL LIKE j* && Variables beginning with j are private LOCAL nCnt, cName |
Example |
LOCAL cMyString AS Character && Use this to document your code. LOCAL oMyForm AS FORM LOCAL oExcel AS "Excel.Application" |
See Also |