Android Question HttpUtils2 if not respond (SOLVED)

Celso

Member
Licensed User
Longtime User
Hi all

I've been hit my head with a small situation, the IF loop don't filter my sentence, follow:

B4X:
Sub TestConnection
    Dim Connect As HttpJob
    Connect.Initialize("Connect", Me)
    Dim txtconn As String 
    txtconn = "https://www.xxx.com.br/check.php?id=" & Tracker.imei
    Connect.Download(txtconn)
    Wait For (Connect) JobDone(Connect As HttpJob)
    If Connect.Success Then
        Dim act As String = Connect.GetString
        Log("CONN "& act)    
        
        If (act = "ok") Then
            Tracker.temnet = "N: Ok"
            isPRO = 0    
            Log("Is Ok") < ----not log
        End If

        If act = "okP" Then
            isPRO = 1
            Log("Pro")
        End If
        
        If (act = "inativo") Then
            Log("Inativo")
        End If
        
    End If
    Connect.Release    
End Sub

I receive, "inativo, ok etc" in act variable (checking by log), but not log when match, so, cant alter value of my variables.
Can someone give me a way.
Thanks a lot.
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

JohnC

Expert
Licensed User
Longtime User
Try this:
B4X:
    If act.IndexOf("okp") > -1 Then
        isPRO = 1
        Log("Pro")
   
    else if act.IndexOf("ok") > -1 Then
          Tracker.temnet = "N: Ok"
           isPRO = 0
           Log("Is Ok")
    End If
   
    If act.IndexOf("inativo") > -1 Then
        Log("Inativo")
    End If

You need to test for "okp" first because if you tested for "ok" first it would return TRUE for BOTH "ok" and "okp" because "ok" is in "okp"
 
Last edited:
Upvote 0

Celso

Member
Licensed User
Longtime User
Try this:
B4X:
    If act.IndexOf("okp") > -1 Then
        isPRO = 1
        Log("Pro")
     
    else if act.IndexOf("okP") > -1 Then
          Tracker.temnet = "N: Ok"
           isPRO = 0
           Log("Is Ok")
    End If
     
    If act.IndexOf("inativo") > -1 Then
        Log("Inativo")
    End If

You need to test for "okp" first because if you tested for "ok" it would trigger BOTH the test for "ok" and "okp" because "ok" is in "okp"

Solve with this solution, TKS for all!
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I updated the code in my previous post, so please just make sure you see the latest version...
 
Upvote 0
Top