Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Vilhelm-Ion Praisach
  Where is Vilhelm-Ion Praisach?
 Resita
 Romania
 Vilhelm-Ion Praisach
 To: Tony Vignone
  Where is Tony Vignone?
 St Augustine
 Florida - United States
 Tony Vignone
 Tags
Subject: RE: IF and IIF are not the same
Thread ID: 396238 Message ID: 396252 # Views: 60 # Ratings: 3
Version: Visual FoxPro 9 SP2 Category: General VFP Topics
Date: Friday, January 24, 2014 3:33:36 AM         
   


Mr. Cetin Basoz explain already the reason.
It's a compiling error.
During the runtime, macros are substitued, so you postpone the compiling step during the runtime.

namea = "a"
?IIF(EMPTY(namea),0,&namea)
is expanded as
?IIF(EMPTY(namea),0,a)
and it's compiled with no error, while
namea = ""
?IIF(EMPTY(namea),0,&namea)
is expanded as
?IIF(EMPTY(namea),0,)
and the attempt to compile it generates the error.

If you replace the macrosubstitution with EVALUATE, as suggested by Mr. Cetin Basoz :
namea = ""
?IIF(EMPTY(namea),0,EVALUATE(""))
raise no error, because is correct from the compiler's point of view, although
?EVALUATE("")
will raise the same error (Missing expression).
This happens because the EVALUATE(something) is compiled as a valid expression, the whole IIF() command line is compiled with no error, and the EVALUATE() argument is evaluated only if it's necessary (as you expected).


> Consider this IF:
>
> a = 77
>
>
namea = "a"
> IF EMPTY(namea) THEN    && FALSE
> 	b = 0
> ELSE
> 	b = &namea
> ENDIF
> ?b
> *------------------
> namea = ""
> IF EMPTY(namea) THEN    && TRUE
> 	b = 0
> ELSE
> 	b = &namea
> ENDIF
> ?b

> In the first IF, the ELSE is invoked.
> In the second IF the ELSE is not invoked so an error will not occur.
>
>
>
> Now consider this equivalent IIF: (it is NOT equivalent when run)
>
>
namea = "a"
> ?IIF(EMPTY(namea),0,&namea)
> namea = ""
> ?IIF(EMPTY(namea),0,&namea)
> 

> In the second IFF, an error occurs on the ELSE part. In other words both the IF and the ELSE parts are evaluated regardless of the truth of the condition tested.
>
> I consider this a bug in VFP. It should have returned 0 and ignored &namea the same way the second IF did above.
>
> Tony



My respects

ENTIRE THREAD

IF and IIF are not the same Posted by Tony Vignone @ 1/23/2014 10:25:12 PM
RE: IF and IIF are not the same Posted by Rick C. Hodgin @ 1/23/2014 10:45:23 PM
RE: IF and IIF are not the same Posted by Tony Vignone @ 1/24/2014 4:59:33 PM
RE: IF and IIF are not the same Posted by Rick C. Hodgin @ 1/24/2014 7:19:52 PM
RE: IF and IIF are not the same Posted by Tony Vignone @ 1/24/2014 8:51:43 PM
RE: IF and IIF are not the same Posted by Victor Espina @ 1/24/2014 10:48:57 PM
RE: IF and IIF are not the same Posted by David Mustakim @ 1/23/2014 10:48:28 PM
RE: IF and IIF are not the same Posted by Cetin Basoz @ 1/24/2014 1:19:08 AM
RE: IF and IIF are not the same Posted by Tony Vignone @ 1/24/2014 5:10:56 PM
RE: IF and IIF are not the same Posted by Vilhelm-Ion Praisach @ 1/24/2014 3:33:36 AM
RE: IF and IIF are not the same Posted by Tony Vignone @ 1/24/2014 5:11:48 PM
RE: IF and IIF are not the same Posted by Vilhelm-Ion Praisach @ 1/24/2014 7:52:01 PM
RE: IF and IIF are not the same Posted by Tony Vignone @ 1/24/2014 8:53:04 PM
RE: IF and IIF are not the same Posted by Paul Gibson @ 1/24/2014 10:18:04 AM
RE: IF and IIF are not the same Posted by Tony Vignone @ 1/24/2014 5:14:00 PM