Android Question Compare Null does not work

Alberto Michelis

Well-Known Member
Licensed User
Hi, I was using this code on older b4a version but now in 8.8 it seams not to be working:

VersionAvisadoVencida = Params.Get("AvisoVencida")
LogColor(VersionAvisadoVencida,Colors.Red)
If VersionAvisadoVencida=Null Then VersionAvisadoVencida=""
LogColor(VersionAvisadoVencida,Colors.Red)
B4X:
        VersionAvisadoVencida = Params.Get("AvisoVencida")
        LogColor(VersionAvisadoVencida,Colors.Red)
        If VersionAvisadoVencida=Null Then VersionAvisadoVencida=""
        LogColor(VersionAvisadoVencida,Colors.Red)
Both Logs are "null"
q.png
 

MarkusR

Well-Known Member
Licensed User
i guess u defined Dim VersionAvisadoVencida As String
try to define as object
B4X:
    Dim VersionAvisadoVencida As Object
Params.Get
returns a object

or a helper that return null as empty string
B4X:
Sub Test2
 
    Dim Params As Map
    Params.Initialize
 
    Dim VersionAvisadoVencida As String
    VersionAvisadoVencida = Para(Params,"AvisoVencida")
    Log(VersionAvisadoVencida)
    If VersionAvisadoVencida = "" Then VersionAvisadoVencida = "123"
    Log(VersionAvisadoVencida)
 
End Sub

Sub Para(Map As Map,Key As String) As String
 
    If Map.Get(Key) = Null Then
        Return ""
    Else
        Return Map.Get(Key)
    End If
 
End Sub
from my point of view
i think its better that a String can not be assigned with a null, only empty string

i think also its a bug because it is not possible to test versus null but the content is null.
 
Last edited:

MarkusR

Well-Known Member
Licensed User
in short
.GetDefault is better
 
Top