Android Question Wait For "Class result"

Rusty

Well-Known Member
Licensed User
Longtime User
I have a class that functions basically like a message box, but does some other stuff.
Is there a way to WAIT for a result from MAIN?
Code: Copy
    CustomMessageBox.Show(Array As String("Card", "Cancel", "Set"))
    Wait For (sf) CustomMessageBox_Result (Result As Int)

If so, how would the code look/function?
Thanks
Rusty
 
Thanks Erel,
I got it to WAIT, but it doesn't return to the calling routine.

MAIN CODE
Code: Copy
...
    Activity.LoadLayout("Main")
    CustomMessageBox.SetTitleText("Please choose a day")
    CustomMessageBox.SetTitleTextColor(Colors.Yellow)
    CustomMessageBox.SetTitleTextSize(30)
    CustomMessageBox.SetBackgroundColor(Colors.Gray)
    CustomMessageBox.SetBitmap( LoadBitmapSample(File.DirAssets, "warning.png", 50dip, 50dip))
    Dim Result As Res
    CustomMessageBox.Show(Answers)
    Wait For CustomMessageBox.btnAnswer_Click Complete (Result As res)
    Log(Result)                           <-----<<<  THIS LINE and below ARE NEVER EXECUTED
    Select Case Result.Index       
        Case 0
            Log("SELECTED  " & Result.index)
        Case 1
            Log("SELECTED  " & Result.index)
    End Select
...
End Sub

CUSTOMMESSAGEBOX CODE
Code: Copy
Sub Class_Globals
...
    Type Res(Index As Int, Value As String)
...
End Sub

public Sub Show(AnswerArray() As String)
shows buttons for clicking all with btnAnswer_Click as the click event
...
End sub

Public Sub btnAnswer_Click As ResumableSub
    Dim btn As Button
    btn = Sender
    Dim Result As Res
    Result.Initialize
    Result.Index = btn.Tag
    Result.Value = btn.Text
    SetVisible(False)
    Log("btnanswer click " & Result)
    Return Result
End Sub
 
Upvote 0
got it to WAIT, but it doesn't return to the calling routine.
Your code is wrong.

1. The sender filter parameter should be inside parenthesis.

2. It is the Show method that needs to be resumable sub and return a ResumableSub object.

You should delete btnAnswer_Click sub and instead write:
Code: Copy
public Sub Show(AnswerArray() As String) As ResumableSub
 ...
 Wait For btnAnswer_Click
 ...
 Return Result
End Sub
 
Upvote 0
Thanks Erel,
So I need to delete the btnanswer_Click routine...? How will Result be created?

Also, I'm not clear on the Wait For statement in MAIN.
Wait For CustomMessageBox.show Complete (Result As Res)
The SHOW routine never runs and thus, no buttons are showing...
Obviously, I don't understand your guidance. Can you help ?
Thanks,
Rusty
 
Upvote 0
Wait For CustomMessageBox.show Complete (Result As Res)
See post @Erel's post #2. This should be
Code: Copy
Wait For (CustomMessageBox.Show(Array As String("Card", "Cancel", "Set"))) Complete (Result as Res)
Note: Since Res is a Type, make sure Main knows about the Type.

Your CustomMessageBox show method becomes (this is just an expansion of @Erel's post #5)
Code: Copy
public Sub Show(AnswerArray() As String) As ResumableSub
'Here goes your original Show method code
shows buttons for clicking all with btnAnswer_Click as the click event
...
'If you had a return in your original Show method, remove it
'Finish up the Show method with the Wait For and the same processing statements that you originally
' used in Sub bntAnswer_Click
    Wait For btnAnswer_Click
    Dim btn As Button
    btn = Sender
    Dim Result As Res
    Result.Initialize
    Result.Index = btn.Tag
    Result.Value = btn.Text
    SetVisible(False)
    Log("btnanswer click " & Result)
    Return Result
End Sub
 
Upvote 0
Thanks! Oliver.
Perfect, it works great. I now understand...
Thanks Erel too!
Rusty
 
Last edited:
Upvote 0
Back
Top