Link to home
Start Free TrialLog in
Avatar of srussell705
srussell705

asked on

VB and a disrespect for NULL?

Is this the best way to limit a NULL problem in vb.net?  I consider it really STUPID to deal with a potential null like this.  C# rules and vb,,,,,  Bad Steve.


For Each oRow As DataGridViewRow In dgRollover.Rows
            If oRow.Cells(0).Value Is Nothing Or DBNull.Value.Equals(oRow.Cells(0).Value) Then
            Else

                If oRow.Cells(0).Value = 1 Then
                    ii = ii + 1
                    'MessageBox.Show(" ID # " & oRow.Cells(3).Value & " presented")
                    CCProcess.RollTransaction(oRow.Cells(3).Value, Me.DateTimePicker1.Value)

Cell(0) is a checkBox in the grid and it it preseted in DATA as a 0 from the server.  

So is there a better way in VB that I am mising?

TIA
 
Avatar of Jorge Paulino
Jorge Paulino
Flag of Portugal image

you can use If String.IsNullorEmpty(oRow.Cells(0).Value) Then
Avatar of srussell705
srussell705

ASKER

Thanks for the reply.

This is an INT column so will that work?  

This column is a checkbox populated with 0 in the data pull from the backend.

You could have used "Not"-keywords and the "And"-operator to leave out the empty if block like this:

If Not oRow.Cells(0).Value Is Nothing And Not DBNull.Value.Equals(oRow.Cells(0).Value) Then
   If oRow.Cells(0).Value = 1 Then
                    ii = ii + 1
   ...
   End If
End If

I'm not sure if that's what you meant. Or do you perhaps just dislike the keyword (Nothing)?
If oRow.Cells(0).Value Is Nothing Or DBNull.Value.Equals(oRow.Cells(0).Value) Then
   ' By the empty if block I meant this block
Else
   If oRow.Cells(0).Value = 1 Then
                    ii = ii + 1
   ...
   End If
End If

You could have used "Not"-keywords and the "And"-operator to leave out the empty if block like this:

If Not oRow.Cells(0).Value Is Nothing And Not DBNull.Value.Equals(oRow.Cells(0).Value) Then
   If oRow.Cells(0).Value = 1 Then
                    ii = ii + 1
   ...
   End If
End If

I'm not sure if that's what you meant. Or do you perhaps just dislike the keyword (Nothing)?

I'll go out on a limb and ask "What is the difference between Nothing and Null?"

Coming from C# it's perplexing that the allowed "nothing" to make it's way into VB.NET in the first place.  I'm sure it would have just toasted all your former code but Nothing is Something and Null is the absence of value.

So why do I have to test for either condition?  Is it a checkbox thing or am I missing the point.  
 
Could not be the better way to do it but is how I do:

If oRow.Cells(0).Value.ToString  =  Then
 ' my code
End If
jpaulino.  Thanks for the reply.

I'll check it out in the morning.  Something looks wrong because it's just to simple.  

This is an int column so I have to see it work.

ASKER CERTIFIED SOLUTION
Avatar of ToFro
ToFro
Flag of Finland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial