Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
IIF()
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Titre:
Re: IIF()
Divers
Thread ID:
00095089
Message ID:
00095188
Vues:
24
>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
Fil
Voir

Click here to load this message in the networking platform