=, Store

This operator and command let you assign a value to a memory variable. The results are the same, but STORE lets you save the same value to multiple variables. Both let you save a single value to all elements of an existing array.

Usage

Variable = uExpression
STORE uExpression TO Variable1 [, Variable2 [...] ]
STORE and = work only on variables and properties. A very common mistake (we can't tell you how often we've made it) is to try to use = to store a value in a field; it doesn't work. In fact, unlike most places in FoxPro, if you have a memvar and field with the same name, STORE and = assume you mean the memvar. (Most commands assume an unqualified, ambiguous reference is to a field.) Because of this, there's never a reason to use the "m." notation when assigning a value with = or STORE, and there's good reason not to—it turns out that assignment is faster without the "m."Another way to save time with STORE is to use a single statement to initialize a bunch of variables:
STORE 0 to nOne, nTwo, nThree, nFour, nFive
is faster than:
nOne = 0
nTwo = 0
nThree = 0
nFour = 0
nFive = 0
STORE is also handy when you're writing generic code because it lets you use a name expression rather than a macro, typically a faster and less resource-intensive operation. That is, if cVarName contains the name of a variable, you can write:
STORE 0 TO (cVarName)
rather than:
&cVarName = 0
If the variable is an existing array and SET COMPATIBLE is OFF, the value of uExpression is stored in every element of the array. This is a quick way to initialize an array. With SET COMPATIBLE ON, the array is overwritten by a single memvar that gets the value of uExpression.Objects change the game with = and STORE. You can use them with objects. What you get is a new reference to the same object, not a copy of the object. There isn't any easy way to create an exact copy of an object. We can think of some brute-force ways, but they're not pretty.

Example

dToday=DATE()
STORE 0 TO nTotal,nCount
DIMENSION aTotals[5]
aTotals=5
oObj1.SomeProperty="Old Value"
oObj2=oObj1
oObj1.SomeProperty="New Value"
? oObj2.SomeProperty          && Returns "New Value"

See Also

Replace, Set Compatible


Back to Table of Contents

Copyright © 2002-2018 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. Click for license .