|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
IIF referencing both conditional parts regardless of condition?IIf(Not (SomeRadiolist.SelectedItem Is Nothing), SomeRadiolist.SelectedItem.Value, DBNull.Value) So the idea of this statement was to detect that if there was no selected item then yield DBNull.Value, otherwise return the value of the selected item. Problem is that this still throws a Null Reference exception in the case where there is no selected item. So I felt inspired to try to find out why by using Reflector (inspired by John Skeet's recent blog entry) and this is the code it yielded: public static object IIf(bool Expression, object TruePart, object FalsePart) { if (Expression) { return TruePart; } return FalsePart; } No surprises there. But it doesn't tell me whats wrong with my code. So I seperated out the logic to this: If optInterpreterProvided.SelectedItem Is Nothing Then dr.Item(COL_InterpreterProvided) = DBNull.Value Else dr.Item(COL_InterpreterProvided) = optInterpreterProvided.SelectedItem.Value End If No error. Whats going on and where's the flaw? Am I such a VB n00b that I don't even know that you can't pass a nothing into a method parameter? Is that the issue here? Thanks, Steven Forget it, I'm an idiot.
Someone tell me how to delete this post before too many people see it please. I don't want the smart people to laugh at me. My wife already does that enough... Steven,
We did already, but I am glad you replied this yourself because I was starting a reply. However, be wise don't use the IIF in VB.Net it is only confusing you and others as you are reading it the next time. Cor Show quoteHide quote "Steven Nagy" <learndot***@hotmail.com> schreef in bericht news:1158124797.312625.123870@h48g2000cwc.googlegroups.com... > Forget it, I'm an idiot. > Someone tell me how to delete this post before too many people see it > please. > I don't want the smart people to laugh at me. My wife already does that > enough... > I don't find it confusing to read...
I just think that IIF should be language specific like it is in C#, not a method in Microsoft.Visualbasic.dll Its the colouring. In C#, the ? and : are visual seperaters making it easy to read. VB lacks this by default and thus becomes harder to read. Just my opinion you understand. Steven Nagy wrote:
> I don't find it confusing to read... But they function differently. IIF evaluates both the true and false> > I just think that IIF should be language specific like it is in C#, not > a method in Microsoft.Visualbasic.dll > > Its the colouring. > In C#, the ? and : are visual seperaters making it easy to read. > VB lacks this by default and thus becomes harder to read. > > Just my opinion you understand. parts regardless of the value of the boolean expression which you discovered. It does this because it is a function. The C# tertiary operator (?:) does not evaluate both. "Steven Nagy" <learndot***@hotmail.com> schrieb: Hm... I find it confusing if the parts connected by '?' and ':' get too >I don't find it confusing to read... long. However, that's just my personal preference. > I just think that IIF should be language specific like it is in C#, not As 'IIf' is a normal function in VB, it gets colored the way all other calls > a method in Microsoft.Visualbasic.dll > > Its the colouring. > In C#, the ? and : are visual seperaters making it easy to read. > VB lacks this by default and thus becomes harder to read. are colored. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Help Clearing data in MaskEditBox Control
dumb question Parsing XML Help with memory/resource use Immediate window Generating SQL on the fly? Proper Way to add tbxXXX.Text to URL Adding parameters to stored procedures AxMSFlexGrid is ambiguous in the namespace AxMSFlexGridLib dbl.quotes in a text file data |
|||||||||||||||||||||||