共用方式為


Variables

A variable is a memory location whose value can change throughout the operation of a program. A variable can contain any data type value. You can change the value of a variable at any time. This option enables you to monitor the status of anything that changes throughout the operation of an application.

Variables exist only while an application is running or in the Visual FoxPro session in which they are created. To specify the scope of a variable, use the LOCAL, PRIVATE, and PUBLIC keywords.

Creating Variables

To create a variable, store a value to a named Visual FoxPro element using the STORE command or the = (equal) operator.

Example

The following examples are simple assignment statements that are functionally equivalent.

STORE 7 TO nVar
nVar = 7

The following example uses a variable, nInc, to hold the value of a loop counter. Visual FoxPro assigns a new value to the variable during each loop.

FOR nInc = 1 TO 10
   ? nInc
ENDFOR

The following example uses a variable, cName, to hold the value of the Firstname field from the Customer table.

USE Customer
STORE Customer.Firstname TO cName

See Also

Access to Variables | = Command | FOR ... ENDFOR Command | LOCAL Command | PRIVATE Command | PUBLIC Command | STORE Command | Data Storage Containers