Android Question IF not working?

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Hi, Im getting a java error but theres not way th ofending line to run because of the preceding IF
PLease see image.
My code is:
B4X:
        Dim guix As String = Params.Get("GUIX")
        Log(guix)
        If Params.Get("GUIX")<>"" And Params.Get("GUIX")<>"null" Then
            Dim Fmax As Long = crypt.decrypt(Params.Get("GUIX"))
            If DateTime.Now>Fmax Then
                VersionNivel = 0
            End If   
        End If
guix is null, you can see it in the attached image, why is the IF true?
I can get what to modify, thanks

PD b4a 5.2
 

Attachments

  • guix.png
    guix.png
    34.7 KB · Views: 187

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Got it! weird thing...

B4X:
        If Params.Get("GUIX")<>"" And Params.Get("GUIX")<>Null Then
=> ERROR

B4X:
        If Params.Get("GUIX")<>Null And Params.Get("GUIX")<>"" Then
=> OK

Is this a bug or a way I need to code?
 
Upvote 0

JordiCP

Expert
Licensed User
Longtime User
It must be done this way.

Params.Get("GUIX") may return a string (empty or not) or nothing (Null) if it has not been found.

Before comparing an object, you need to make certain that it is not NULL, otherwise you will get an error.
Also, the "if" condition is evaluated from left to right. So, if the first condition fails, it will not evaluate the second.

(In other languages as C, the first comparison would be made to the pointer holding the object. If it is not Null, proceed with checking the content. )
 
Upvote 0
Top