Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
WEXIST() problem
Message
 
To
21/01/2002 10:08:15
General information
Forum:
Visual FoxPro
Category:
Reports & Report designer
Miscellaneous
Thread ID:
00606840
Message ID:
00608416
Views:
18
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.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform