Android Question wait for does not wait for the return values

Makumbi

Well-Known Member
Licensed User
Please help iam trying to return values from the api but the wait for URL just jumps out and does not wait to return the values thank you in advance
B4X:
cursor1.Close
    pro.Initialize
    Dim rs As Object = pro.checkuser
    wait for (rs) Complete (Value As String)

below is the standard class
B4X:
Sub Class_Globals
    Private xui As XUI
    Public SQL As SQL
    Dim cursor1 As Cursor
    'Dim checkuser As String
End Sub

'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
    'Return Me
End Sub


Sub checkuser
    'Log(a)
    If IsConnectedToInternet= True Then
        'cursor1 = Starter.SQL1.ExecQuery("SELECT code || phone AS Phone FROM Register")
        Dim SQLQry As String = "DELETE FROM Allacounts"
        B4XPages.MainPage.SQL.ExecNonQuery(SQLQry)
        Dim SQLQry As String = "DELETE FROM student"
        B4XPages.MainPage.SQL.ExecNonQuery(SQLQry)
        Dim SQLQry As String = "DELETE FROM Balances"
        B4XPages.MainPage.SQL.ExecNonQuery(SQLQry)
      
        'Chr(0xF19D)
        'Starter.SQL1.ExecNonQuery("DROP TABLE IF EXISTS Balances")
      
        'Starter.SQL1.ExecNonQuery("CREATE TABLE Balances (Account Text,Names text, Class text,Stream text,Amount REAL, ID INTEGER)")
        cursor1 = B4XPages.MainPage.SQL.ExecQuery("SELECT phone AS Phone,Sex FROM Register")
        If cursor1.RowCount > 0 Then
            '    For i = 0 To cursor1.RowCount - 1
            cursor1.Position =0
            Dim Phoneq As String
            Phoneq = cursor1.Getstring("Phone")
          
            Dim sx As String
            sx = cursor1.Getstring("Sex")
            'Next
        End If
        Dim CustID As String = Phoneq' Customer ID
        Dim jt As HttpJob
        jt.Initialize("", Me)
        jt.Download("http://108.175.14.200/KABOJJAAPPAPI/api/HandlerVBRegistration/Registrationdata?ne=" & CustID & "&cy=" & sx)
        Sleep(0)
        'jt.GetRequest.Timeout = 2000 ' 10 seconds
        Wait For (jt) JobDone(jt As HttpJob)
        If jt.Success Then ' if job is success (http status code 200)
            Dim RetVal As String
            RetVal = jt.GetString
            If jt.GetString = "[]" Then
                'MsgboxAsync("No Records to Upload Yet for: " & CustID ,"SMIS")
                '    Return
                'MsgboxAsync("Your Account is  Not Registered Please Contact the School  for More Details Thank You " ,"SMIS")
      
                '    Return "Not Registered Parent"
                Dim sf As Object = xui.Msgbox2Async("Your Account is  Not Registered Please  Click on Yes Button to Fill the Details of your Child. Please Indicate Child's Name , Class and Stream and other Details Or Contact the School for More Details Thank You", "New Complaint", "Yes", "Cancel", "No",Null)
                Wait For (sf) Msgbox_Result (Result As Int)
                If Result = xui.DialogResponse_Positive Then
                    'Log("Deleted!!!")
                    B4XPages.ShowPage("failedlogin")
                End If
                          
            Else
          
                Dim jpt As JSONParser
                jpt.Initialize(jt.GetString)
                '    Log(jpt) ' will pr
                Dim quotes As List = jpt.NextArray
                For Each quot As Map In quotes
                    Log("Account: " & quot.Get("Account"))
                    Log("Name: " & quot.Get("Name"))
                    Log("Category: " & quot.Get("Category"))
                    Log("Froms: " & quot.Get("Froms"))
                    Log("Tos: " & quot.Get("Tos"))
                    Log(DateTime.Date(JsonDateToTick( quot.Get("Froms"))))
                    Dim l As Long
                    DateTime.DateFormat = "dd/MM/yyyy" ' "1961-08-29"
                    Dim datestring As String = DateTime.Date(JsonDateToTick( quot.Get("Froms")))
                    l = DateTime.DateParse(datestring)
                    DateTime.DateFormat = "dd/MM/yyyy"
                    Log(DateTime.Date(l))
              
                    Log(DateTime.Date(JsonDateToTick( quot.Get("Tos"))))
                    Dim lt As Long
                    DateTime.DateFormat = "dd/MM/yyyy" ' "1961-08-29"
                    Dim datestring As String = DateTime.Date(JsonDateToTick( quot.Get("Tos")))
                    lt = DateTime.DateParse(datestring)
                    DateTime.DateFormat = "dd/MM/yyyy"
                    Log(DateTime.Date(lt))
                    cursor1 = B4XPages.MainPage.SQL.ExecQuery("SELECT ID FROM Allacounts")
                    'cursor1 = SQL1.ExecQuery("SELECT Phone FROM Register")
                    If cursor1.RowCount > 0 Then
                        For i = 0 To cursor1.RowCount - 1
                            cursor1.Position = i
              
                            Dim NewID As Int
                            NewID = cursor1.GetInt("ID")
                        Next

                    End If
          
                    NewID = NewID +1      ' add 1 to the ID number to make a new ID field
  
                    '    Starter.SQL1.ExecNonQuery("INSERT INTO Allacounts VALUES('" & quot.Get("Account") & "','" & CustID  & "','" & NewID & "')")
                    'End If
                    'Grab the last ID number which is the highest number
              
                    B4XPages.MainPage.SQL.ExecNonQuery2("INSERT INTO Allacounts VALUES(?,?,?)", Array As Object(quot.Get("Account"), CustID,NewID))
  
          
                    'trap user from here
              
  
                Next
          
                'Return "Active"
            End If
        End If
        'jt.Release
      
                  
  
    Else
      
        xui.MsgboxAsync("Error Connecting to the Server Please Check Your Internet Connection Or Load Mbs", "Server Error")
      
        't1.Enabled = False

    End If
End Sub


Sub JsonDateToTick(s As String) As Long
    Dim mt As Matcher = Regex.Matcher("\d+", s)
    If mt.Find Then
        Return mt.Match
    End If
    Log("Invalid date: " & s)
    Return 0
End Sub
Sub IsConnectedToInternet As Boolean
    Dim ctxt As JavaObject
    Dim NetworkInfo As JavaObject = ctxt.InitializeContext.RunMethodJO("getSystemService", Array("connectivity")).RunMethod("getActiveNetworkInfo", Null)
    If NetworkInfo.IsInitialized Then
        Return NetworkInfo.RunMethod("isConnectedOrConnecting", Null)
    Else
        Return False
    End If
End Sub
 
Last edited:

OliverA

Expert
Licensed User
Longtime User
Please help iam trying to return values from the api but the wait for URL just jumps out and does not wait to return the values thank you in advance
We need some more precision here
If you have the following code
B4X:
cursor1.Close
    pro.Initialize
    Dim rs As Object = pro.checkuser
    wait for (rs) Complete (Value As String)
    'Let's add log
    Log("Hey I'm done with the Wait For")
are you saying that the log statement is printed before the Wait For actually is done?
OR
Is the activity continuing (as expected), even though you have the Wait For. Please note that the Wait For will "pause" B4XPage_Created, but will not stop anything else that should run after B4XPage_Created from running. You may need to relocate the Wait For into a different B4XPage event (maybe Appear?).
 
Last edited:
Upvote 0

Peter Simpson

Expert
Licensed User
Longtime User
Well for starters the following URL does not return anything, the api can't be setup correctly if it's supposed to return a JSON feed.

B4X:
http://108.175.14.205/KABOJJAAPPAPI/api/HandlerVBRegistration/Registrationdata?ne=0782911364&cy=Father
The above will not return anything if the api is not setup correctly from the start.
If you type into your browser the above URL, what does it return???

Obviously the following shows a basic webpage
B4X:
http://108.175.14.205/
 
Upvote 0

Makumbi

Well-Known Member
Licensed User
Well for starters the following URL does not return anything, the api can't be setup correctly if it's supposed to return a JSON feed.


The above will not return anything if the api is not setup correctly from the start.
If you type into your browser the above URL, what does it return???

Obviously the following shows a basic webpage
B4X:
http://108.175.14.205/
thank you my api configurations had issues i have solved it and it is now ok
 
Upvote 0
Top