Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
IIF() Evaluates Differently Than IF?
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00044321
Message ID:
00044343
Vues:
29
>Here's an odd one. The following code returns two different answers, even though they should be identical:
>
>****************
>* The following code makes vp_dbfname = ""
>****************
>iif(EMPTY(thisform.ctextbox1.Value),vp_dbfname = "", ;
> vp_dbfname = thisform.ctextbox1.Value)
>
>****************
>* This code makes vp_dbfname = thisform.ctextbox1.Value
>****************
>if EMPTY(thisform.ctextbox1.Value)
> vp_dbfname=""
>else
> vp_dbfname = thisform.ctextbox1.Value
>endif

Hi Michael!

IIF() is something diiferent, than you think it.

The sintax of IIF() is:

IIF(lExpression, eExpression1, eExpression2)

In your example, you don't use expression, instead, you use a statement. (assigment) But VFP, in this case thinks, that it is an expression, and it evaluates it. VFP tests the equality.
And depending on the result, gives .T. or .F., depending on the value of vp_dbfname.
IIF is a function, which gives back either the value of the first, or the value of the second expression.
So, you should use:

vp_dbfname = iif(EMPTY(thisform.ctextbox1.Value), "", thisform.ctextbox1.Value)

Good luck!

BB
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform