Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
IIf not working as expected?
Message
De
14/06/2006 13:13:34
Keith Payne
Technical Marketing Solutions
Floride, États-Unis
 
 
À
14/06/2006 13:09:00
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
01129039
Message ID:
01129087
Vues:
20
>>>>>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.
>
>Hmm I don't see those notes in the VS2005 documentation.
>Cetin

Maybe the function was changed in 2005 and now it does perform short-circuit evaluation.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform