Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Rick C. Hodgin
  Where is Rick C. Hodgin?
 Indianapolis
 Indiana - United States
 Rick C. Hodgin
 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: 396242 # Views: 87 # Ratings: 3
Version: Visual FoxPro 9 SP2 Category: General VFP Topics
Date: Thursday, January 23, 2014 10:45:23 PM         
   


> 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

No. It's not a bug.

All of those input values are parameters passed to the IIF() function. They are passed as input parameters, so the existence of &namea is evaluated and converted at that point (before it's passed) so that the input value arriving at VFP's IIF() function is the value of &namea. This is true even if that value is ultimately not used based on the logic condition of the first parameter, which is also evaluated as a passed parameter.

-----
Best regards,
Rick C. Hodgin

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