Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
LOCAL lcCommand
lcCommand = "y = 5 + 5"
x = SECONDS()
FOR lnCounter = 1 TO 1000000
y = 5 + 5
ENDFOR
?"Without: " + TRANSFORM(SECONDS() - x) + " seconds"
x = SECONDS()
FOR lnCounter = 1 TO 1000000
&lcCommand
ENDFOR
?"With: " + TRANSFORM(SECONDS() - x) + " seconds"
lcCommand = "5 + 5"
x = SECONDS()
FOR lnCounter = 1 TO 1000000
y=EVALUATE(lcCommand)
ENDFOR
?"With EVALUATE(): " + TRANSFORM(SECONDS() - x) + " seconds"
lcCommand2 = "5 + 5"
x = SECONDS()
FOR lnCounter = 1 TO 1000000
y=&lcCommand
ENDFOR
?"With &: " + TRANSFORM(SECONDS() - x) + " seconds"
[code]
* Create a cursor and fill it:
CREATE CURSOR jnk ( one N(3) )
FOR lnI = 1 TO 10
APPEND BLANK
replace one WITH lnI
ENDFOR
x = SECONDS()
FOR lnI = 1 TO 200
lcFile = 'fileNameEx'+TRANSFORM(lnI)+'.tmp'
COPY TO (lcFile)
ENDFOR
?"With (): " + TRANSFORM(SECONDS() - x) + " seconds"
x = SECONDS()
FOR lnI = 1 TO 200
lcFile = 'fileMacro'+TRANSFORM(lnI)+'.tmp'
COPY TO &lcFile
ENDFOR
?"With &: " + TRANSFORM(SECONDS() - x) + " seconds"
datadir="D:\My_Data\"
FOR i=1998 TO 2003
ii=STR(i,4)
sfx=IIF(i=2003, "old", "new")
SELECT * ;
FROM [COLOR=red](datadir+"My_Table"+ii+sfx)[/color] ;
WHERE &wkd AND &no_std AND &in_list ;
GROUP BY 1,2,3 ORDER BY 1,2,3 ;
INTO CURSOR tmp
SELECT avg_tmp
APPEND FROM DBF("tmp")
NEXT
with the caveat that EVALUATE() can return an incorrect result when used in the WHERE portion of a SQL command.
Macro substitution statements that appear in DO WHILE, FOR, and SCAN are evaluated only at the start of the loop and are not reevaluated on subsequent iterations. Any changes to the variable or array element that occur within the loop are not recognized.
The FoxPro language compiler parses the program and replaces a name expression with the value during the first pass; from that point on, only the value, not the variable, is used. The FoxPro compiler leaves a macro substitution as a reference to the variable that is not resolved until the program is executed.
The only situation where macro substitution is still required is when the expression to evaluate contains the command to be executed, in whole or in part,...
lcTest=[1+playerno]
create table entrylist (Entryno I(3), Playerno I(3), Weight N(4,1), Date D(8))
insert into entrylist values (1, 1, 4, {09/25/04})
insert into entrylist values (1, 2, 3.8, {09/25/04})
insert into entrylist values (2, 5, 4.2, {09/25/04})
insert into entrylist values (2, 7, 4.4, {09/25/04})
insert into entrylist values (3, 4, 4, {09/25/04})
SELECT * from entrylist WHERE EVALUATE(lcTest)=2
SELECT entrylist
LOCATE FOR EVALUATE(lcTest)=2
SELECT * from entrylist WHERE EVALUATE(lcTest)=2
lcTest=[entrylist.playerno]
create table entrylist (Entryno I(3), Playerno I(3), Weight N(4,1), Date D(8))
insert into entrylist values (1, 1, 4, {09/25/04})
insert into entrylist values (1, 2, 3.8, {09/25/04})
insert into entrylist values (2, 5, 4.2, {09/25/04})
insert into entrylist values (2, 7, 4.4, {09/25/04})
insert into entrylist values (3, 4, 4, {09/25/04})
SELECT * from entrylist WHERE EVALUATE(lcTest)=4 && Records returned
SELECT * from entrylist WHERE EVALUATE(lcTest)=1 && No Records returned
GO TOP IN "entrylist"
SELECT * from entrylist WHERE EVALUATE(lcTest)=4 && No Records returned
SELECT * from entrylist WHERE EVALUATE(lcTest)=1 && Records returned
create table entrylist (Entryno I(3), Playerno I(3), Weight N(4,1), Date D(8))
insert into entrylist values (1, 1, 4, {09/25/04})
insert into entrylist values (1, 2, 3.8, {09/25/04})
insert into entrylist values (2, 5, 4.2, {09/25/04})
insert into entrylist values (2, 7, 4.4, {09/25/04})
insert into entrylist values (3, 4, 4, {09/25/04})
lcTest=[playerno]
SELECT * from entrylist WHERE EVALUATE(lcTest) = 4 && One Record returned
lcTest=[[COLOR=red]entrylist[/color].playerno]
SELECT * from entrylist WHERE EVALUATE(lcTest) = 4 && All Records returned