Android Question The Use of Wait for a Sub with InputMapAsync to Complete Does not Continue to Next Sub

Mahares

Expert
Licensed User
Longtime User
The DisplayQuery sub is never reached unless I extract the code from SelectClasses sub and put it in Activity_Resume sub. The complete project code is shown below. Is there a way to have SelectClasses sub on its own as I have it in the project.
Thank you

B4X:
Sub Globals
    Private strQuery As String
    Private ClassPicked As String
End Sub

Sub Activity_Create(FirstTime As Boolean)
 
End Sub

Sub Activity_Resume
    Wait For (CallSub(Me,"SelectClasses")) Complete (Result As Object)
    Log("classes: " & ClassPicked)
    DisplayQuery
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub SelectClasses
    Dim m As Map=CreateMap("MTR":False, "PJK":False, "PLU":False, "HGU":False)
    Dim k As Int
    InputMapAsync(m, "Select a Class or more", False) 'There Is no input multi Select keyword, therefore we use map
    Wait For InputMap_Result
    For Each c As String In m.Keys
        If m.Get(c)=True Then
            ClassPicked =$"'${c}',"$ & ClassPicked
            k=k+1
        End If
    Next
    If k=0 Then
        Msgbox2Async("Click 'Yes' to select all or 'No' to exit", _
        "Select ALL classes?","Yes","","No",Null,False)
        Wait For Msgbox_Result (Result As Int)
        If Result = DialogResponse.POSITIVE Then
            ClassPicked="ALL"
        Else
            ToastMessageShow("No classes were selected, exiting", False)
            Activity.Finish
        End If
    Else
        ClassPicked=ClassPicked.SubString2(0,ClassPicked.LastIndexOf(","))  'remove last trailing comma
    End If
    Log("At the end of SelectClasses " & ClassPicked)
End Sub

Sub DisplayQuery
    If ClassPicked="ALL" Then
        strQuery= $"SELECT WELL_NAME, WELL_NO, CLASS FROM Base_Wells
        ORDER BY WELL_NAME COLLATE NOCASE"$
    Else
        strQuery= $"SELECT WELL_NAME, WELL_NO, CLASS FROM Base_Wells WHERE CLASS IN(${ClassPicked})
        ORDER BY WELL_NAME COLLATE NOCASE"$
    End If
    Log("The query syntax is: " & strQuery)
End Sub
 

Attachments

  • InputMapAsyncWithWaitFor.zip
    8.6 KB · Views: 221
Last edited:
Top