Tuesday, May 11, 2010

How to check if a double or integer or any numeric value is NULL

If you try to check on .NET using condition line

If myInteger Is Nothing=True Then

'Print something here

End If

Likely if the value of the integer is 0 (instead of real null value) the condition will become true and the code inside if statement will be executed. This is very fraustrating if the real purpose of the code is to check if the particular variable is really NULL

The better way to work around is to declare your integer as

Dim myInteger as Nullable(Of Integer)

or if it is double

Dim myDouble as Nullable(Of Double)

If you try to do the NULL test again using the code above, this time if the integer has value 0 the statement won't take it as true. Only if the integer is really NULL value the statement will be executed.

Just a little simple tricks. ;) If you don't know how to do it, it will take you about 10-20 minutes or so googling around and figuring out how this can be done.. justl ike me.. =D

No comments: