B4J Question A Resumable case

LucaMs

Expert
Licensed User
Longtime User
I want to wait for an event whch can be raised both by an user's choice (he should press one of two buttons, "OK" or "NO") or by a timer tick event (time out).

Is there a way to do it without needing to use a global variable?
 

Attachments

  • Resumable case.zip
    2.6 KB · Views: 198
Last edited:

udg

Expert
Licensed User
Longtime User
I didn't study the code yet, but what about adding an option (e.g. Autocancel ) to a standard XUI Dialog where a timer closes it with the "dismiss" result (or a default one)?
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I didn't study the code yet, but what about adding an option (e.g. Autocancel ) to a standard XUI Dialog where a timer closes it with the "dismiss" result (or a default one)?
First of all, thank you for your help, U.

A dialog or a "normal layout" is the same thing; I could do as you wrote but then I would not be able to know if the dialog was closed by the timeout or by the user action (that's why I asked ...
Is there a way to do it without needing to use a global variable?
 
Upvote 0

udg

Expert
Licensed User
Longtime User
I see..
Well, the "dismissed" return value could be a new one (in addition to POSITIVE, NEGATIVE..) so in that case you'll know that it was the timer to close the dialog.
As said, I didn't yet study the new XUI Dialogs so I can't be of further help on the specific subject, but you got the idea.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Your code is wrong. You cannot wait for a sub that doesn't return a ResumableSub.

You should do something like this:
B4X:
Sub AppStart (Form1 As Form, Args() As String)
   MainForm = Form1
   MainForm.RootPane.LoadLayout("layMain") 'Load the layout file.
   tmr.Initialize("tmr", 1000)
   MainForm.Show
   Wait For TaskCompleted(Result As String)
   lblAnswer.Text = Result
End Sub


Sub Chosen_Click
   tmr.Enabled = False
   Dim btnSender As Button = Sender
   Dim Answer As String = btnSender.Tag
   SetViews
   RaiseEvent(Answer)
End Sub


Private Sub RaiseEvent(Answer As String)
   CallSubDelayed2(Me, "TaskCompleted", Answer)
End Sub

Private Sub tmr_Tick
   mCounter = mCounter + 1
   lblCount.Text = mCounter
   If mCounter = 5 Then
       tmr.Enabled = False
       SetViews
       RaiseEvent("Time out")
   End If
End Sub

I would have used B4XDialog instead.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…