Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss.
 From: Cetin Basoz
  Where is Cetin Basoz?
 Izmir
 Turkey
 Cetin Basoz
 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: 396249 # Views: 71 # Ratings: 3
Version: Visual FoxPro 9 SP2 Category: General VFP Topics
Date: Friday, January 24, 2014 1:19:08 AM         
   


> 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

Yes they are not the same. One of them is an inline version. That means it is a single line "command". You are using & there and that is the reason you think it is getting evaluated. As an argument nothing is getting evaluated there. It is just that for that line to execute & is expanded. & is not needed there anyway. You can use evaluate() instead. To see that nothing gets evaluated check this sample:

? iif(.t., 1, 1+"A")




Cetin Basoz

Give some sample data in code for your question - here is the tool you need to generate the code

My Blog


MongoDb Certified Developer
MongoDb Certified DBA


Support Wikipedia

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