Bug? If not recognizing null

RVP

Active Member
Licensed User
Longtime User
I have the following test

B4X:
        If (valSDate <> Null  AND valSDate <> "" AND valSDate.Length>0) Then
 
            dteScheduled.SetDate(DateTime.DateParse(valSDate),True)
        Else
            dteScheduled.SetDate(-1,True)
        End If

Per the debugger

valSDate
value = null

However the code still runs the first part of the if statement, instead of the else section
 
Last edited:

RVP

Active Member
Licensed User
Longtime User
Similar to this
B4X:
Dim myMap AsMap
 
    myMap.Initialize
    myMap = DBUtils.ExecuteMap(Main.SQL1,SQLScripts.LoadTimeDetail(rowId),Null)
 
Dim tmpstDate AsString : tmpstDate = myMap.Get("st")
Dim tmpetDate AsString : tmpetDate = myMap.Get("en")
 
If ( tmpstDate = Null OR tmpstDate = "" OR tmpstDate.Length=0) Then
    txtStartDate.SetDate(-1,True)
Else
    txtStartDate.SetDate(DateTime.DateParse(tmpstDate),True)
EndIf



How do I check for a null value then?
 

MaFu

Well-Known Member
Licensed User
Longtime User
Similar to this
B4X:
Dim myMap AsMap

    myMap.Initialize
    myMap = DBUtils.ExecuteMap(Main.SQL1,SQLScripts.LoadTimeDetail(rowId),Null)

Dim tmpstDate AsString : tmpstDate = myMap.Get("st")
Dim tmpetDate AsString : tmpetDate = myMap.Get("en")

If ( tmpstDate = Null OR tmpstDate = "" OR tmpstDate.Length=0) Then
    txtStartDate.SetDate(-1,True)
Else
    txtStartDate.SetDate(DateTime.DateParse(tmpstDate),True)
EndIf



How do I check for a null value then?

And another point:
if a string is empty then it's length is always 0, if a string is not empty the length cannot be 0.
Therefore it's no need for both checks (tmpstDate = "" OR tmpstDate.Length=0), you only need one.
 
Top