NullPointerException on a string comparaison

jnbarban

Member
Licensed User
Longtime User
Hello,

I have a string which contains sometimes a Null value, when i test :

"If sDateDispatch <> Null Then"
I don't have the exception on this, but it don't work
because the exception appears when i test :
"if sDateDispatch.CompareTo("1901-01-01") >0 then "

The code :

If sDateDispatch <> Null Then
If sDateDispatch.CompareTo("1901-01-01") >0 Then
Return
End If
End If

How to test this correctly?
Thank you
 

jnbarban

Member
Licensed User
Longtime User
The Null value Come from a Cursor.
The SQL contains a "left outer join" with no return
 

miguelconde

Member
Licensed User
Longtime User
I'm unable to reproduce it. Can you upload a small project that demonstrates this problem?

I had the same error, to solve it I had to put a value "" void in the fields of the database and thereby eliminate the null. The problem is with null fields and its treatment as a string in the string object v4a
 

bees

Member
Licensed User
Longtime User
Hello,

I have a string which contains sometimes a Null value, when i test :

"If sDateDispatch <> Null Then"
I don't have the exception on this, but it don't work
because the exception appears when i test :
"if sDateDispatch.CompareTo("1901-01-01") >0 then "

The code :

If sDateDispatch <> Null Then
If sDateDispatch.CompareTo("1901-01-01") >0 Then
Return
End If
End If

How to test this correctly?
Thank you

I could not find an IsNull() function. Would really like to have one .
For strings you could make a function.

Sub IsNullString(cString As String) As Boolean

Try
If cString.Length >= 0 Then
Return False
End If
Catch
Return True
End Try

End Sub
 
Top