Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
WEXIST() problem
Message
 
À
21/01/2002 10:08:15
Information générale
Forum:
Visual FoxPro
Catégorie:
Gestionnaire de rapports & Rapports
Divers
Thread ID:
00606840
Message ID:
00608416
Vues:
17
Let me jump in and say that you are treating the IIF function as if it were an IF .. ELSE .. ENDIF structure. It's not.

Here's what the IIF function would look like if you were to write it in Foxpro:

FUNC MyIIF
LPARA What, LTrue, LFalse
If EVAL(What)
Return LTrue
Else
Return LFalse
Endif
Endfunc

If you pass a function as either the true or false parameter, it will be run BEFORE entering the function and will pass the return value from that function to the MyIIF function. If you attempt to perform an ASSIGNMENT in either the true or false parameter it will not function the way it would in an actual IF.. ENDIF statement. It's not like the IF .. ENDIF that executes code in the true/false segments AFTER analysis of the conditional test.

So, if you try to enter "WasReportPrinted =.t." as the "true" parameter to IIF, what it will try to do is compare the left side of the arguement (the value contained in the variable WasReportPrinted ) to the right side of the arguement (.t.) before entering the function. Then if the test condition evaluates true, you get the return value of the evaluation (WasReportPrinted =.t.) which depends on the preexisting state of the variable "WasReportPrinted ". If the variable contains something that cannot be compared to a logical value, you will receive an error.

Put another way, the Foxpro IIF() function is like the tertiary (ternary? I can use it I just can't spell it) operator in C:

int a, b, c;
a=3;
b=4;
c=0;
c=(a
C will be assigned (=) the value 3 (contained in a) because a
Back to Foxpro.

Since WEXIST() returns a logical true or false anyway, If you simply wanted to assign the return value from WEXIST('Printing...') to the variable WasReportPrinted, you would write

WasReportPrinted = WEXIST('Printing...')


Hope this helps.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform