>Hello,
> Is an IIF() faster than an If-Else-Endif statement?
As with most things in life, it depends on your definition of "faster." As several others have mentioned, there is a negligible speed difference if you are using simple expressions [=IIF(x==y, value1, value2]. Complex expressions that have nested IIFs and subfunctions are a little trickier.
However, I find that the real advantage to IIF() is it's ease of use in SELECT statements. One of my favorite code algorithms is to have several optional fields on my query form, and based on what the user enters, filter my select like so:
SELECT table1.x, table1.y, table1.z ;
FROM table1 ;
WHERE EVAL(IIF(!EMPTY(field1), "x = field1","")) ;
AND EVAL(IIF(!EMPTY(field2), "y = field2",""))
INTO CURSOR csrResults
When you have four or five fields on a form, and you don't want to create a WHEN string that will be macro-expanded, this approach is a beauty, and actually does execute faster than a macro-expanded string (at least it did under 2.6; haven't had need to try it under VFP).
Précédent
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement