Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Macro substitution / evaluate()

Status
Not open for further replies.

MrFancyteeth

Programmer
Mar 18, 2003
90
GB
I've been using macro substitution for a while, but just found the evaluate() function in Visfox help.

quote:"Whenever possible, use EVALUATE( ) or a name expression to replace macro substitution using &. EVALUATE and name expressions execute faster than macro substitution."

However i've tried using it and it produced errors.

i would normally write something like:
csql="*"
SELECT &csQl FROM table1

which works but,

csql="*"
SELECT evaluate(csQl) FROM table1

doesn't work.

any ideas?

MrF


 
Because Evaluate() returns a "value" you can't use it in a command like this. You could use it in a WHERE condition or anywhere else an expression is expected. The help file example shows this:
Code:
cMathFunc="INT(4.33)"
nResult=EVALUATE(cMathFunc)
?nResult

OR

cMathFunc="INT(4.33)"
nResult=&cMathFunc
?nResult
These work the same, and unless you put them in a "big" loop, you'll never notice the difference. The speed difference comes about because a macro has to be parsed and syntaxed each time, where the evalute() expression only needs to do this the first time it's run.

Rick
 
Here is another example:

Code:
REPLACE &fldname WITH &newdata  && works
REPLACE &fldname WITH EVAL(newdata)  && works a wee bit faster!
REPLACE EVAL(fldname) WITH EVAL(newdata)  && does NOT work!

A while back I did a test in dBase 5 with some simple FOR loops (100,000 iterations) and found that EVALUATE(cVar) was twice as fast as &cVar (macrosubstitution), so there are clear reasons to use it WHEN POSSIBLE, and especially when you are looping a lot. In my case, I modified my code but NO ONE noticed a speed increase! Of course the program took 40 minutes to run, so who would notice a minute or two less? At least I feel better that I did the "right thing" even if those accumulating microseconds didn't get noticed.

As noted above you cannot use EVALUATE() or () everywhere.

This is similar situation with VARTYPE() and TYPE(). VARTYPE() is faster but not as flexible and powerful.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top