Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IIf not working as expected?
Message
From
14/06/2006 13:01:13
Keith Payne
Technical Marketing Solutions
Florida, United States
 
 
To
14/06/2006 12:34:17
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01129039
Message ID:
01129082
Views:
15
>>>The following line is not working as expected:
>>>
>>>
>>>Dim lcImpDate As String  = _
>IIf(IsStringBlank(Trim(Request.Form("txtImpDate").Replace("/",""))),"", _
>FormatDateSubmit(Request.Form("txtImpDate")))
>>>
>>>
>>>IsStringBlank() and FormatDateSubmit() are other functions in my class. The IsStringBlank() IS returning true, but the FormatDateSubmit() function is still being called even though it is in the "false" part of the IIf. Any ideas what I'm missing here?
>>>
>>>Thanks,
>>>KP
>>
>>Kevin,
>>
>>That behavior is normal for IIf. You have to use an If..Then with AndAlso or OrElse to get short-circuit evaluation.
>
>Keith,
>While it might be normal for VB it sounds to be a bug to me. In documentation it says it's a counterpart of "?" operator of C. ? operator's behavior is absolutely is not like that. Both C and VFP (iif()) correctly only call the relevant part.
>Cetin

I would like there to be a true equivalent of ? in VB.NET. It would certainly make some of the code more concise. But I think that is antithetical to the design goals for VB (more verbose, more straightforward, less subtle).

From the help for IIf():
Note The expressions in the argument list can include function calls. As part of preparing the argument list for the call to IIf, the Visual Basic compiler calls every function in every expression. This means that you cannot rely on a particular function not being called if the other argument is selected by Expression.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform