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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

& 1

Status
Not open for further replies.

monikai

Programmer
Aug 4, 2002
358
PL
Hi,[sunshine]
are the macros (&string) make the program slower?
much or little?

Regards from Monika (Warszawa - Poland)
(monikai@yahoo.com)
 
I agree, but that still doesn't explain why only a single record would be returned by:

lcTest=[playerno]
SELECT * from entrylist WHERE EVALUATE(lcTest) = 4 && One Record returned

...appears to be working and no longer referencing the active record in entrylist, however that's not the case since:

lcTest=[playerno]
SELECT * from entrylist WHERE EVALUATE(lcTest) = 1 && No Records returned

...I cannot come up with a logical explanation for this. The fact that evaluate() is referencing the current record in entrylist explains every case except this one. If this example fit the mold, the first SQL statement having EVALUATE(lcTest) = 4 in it's where clause would return all records, not just one, since as you say it is equivalent to having "Where .T.".

boyd.gif

 
() certainly does not work as one would think it should be when used in a WHERE clause. In a perfect world this usage should really throw an error.

Using '&lcTest' works as desired in all cases.

Brian
 
Brian,

I am not sure if I am following you or just respectfully disagree.


Jim,

() works fine as long as you don't expect the value to change. & is slower because it is re-evaluated every time it is called whereas () is not.


Code:
DECLARE arTable2Open[3]
arTable2Open[1] = 'employee'
arTable2Open[2] = 'pay'
arTable2Open[3] = 'vacation'


FOR lni = 1 to 3
  lcTable2Open = arTable2Open[lni]
  SELECT 0
  USE (lcTable2Open)
ENDFOR

* works fine - even with the changing value.



Jim Osieczonek
Delta Business Group, LLC
 
jimoo, your code example works because it's completely inside the loop. As I recall some languages warn about changing values controlling the loop, I think JavaScript was one that comes to mind.
Code:
FOR lni = 1 to EVAL(lnMax)
  lcTable2Open = arTable2Open[lni]
  SELECT 0
  USE (lcTable2Open)
  IF ALIAS()<>""
     lnMax=lni  && this assignment probably doesn't force exit
  ENDIF
ENDFOR
Another example could be this one where the value passed is the data contents and is evaluated only once at the entry point.

DO myProg WITH (myVar)

Apparently there is some initial evaluation that is done in the SQL's WHERE clause that is not repeated within the command. Interesting little quirks, aren't they?

dbMark
 
Mark

I am more confused (respectfully)


As I recall some languages warn about changing values controlling the loop...


You're right, change the controlling value of a loop will cause a problem in any language.

In VFP this is often caused by the system variable _TALLY variable - such as

FOR lni = 1 TO _TALLY

and _TALLY is later changed as a result of another operation.

However, I don't think that is the question and none of the prior examples in this thread deal with the controlling value. It is whether the & or () work.

I think the example I provided demonstrates either can work, but () is usally more efficient and the value can change as with &.




Jim Osieczonek
Delta Business Group, LLC
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top