B4J Question A Resumable case

Discussion in 'B4J Questions' started by LucaMs, Jan 13, 2019.

Tags:
  1. LucaMs

    LucaMs Expert Licensed User

    I want to wait for an event whch can be raised both by an user's choice (he should press an 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?
     

    Attached Files:

  2. udg

    udg Expert Licensed 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)?
     
    LucaMs likes this.
  3. LucaMs

    LucaMs Expert Licensed User

    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 ...
     
  4. udg

    udg Expert Licensed 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.
     
  5. Erel

    Erel Administrator Staff Member Licensed User

    Your code is wrong. You cannot wait for a sub that doesn't return a ResumableSub.

    You should do something like this:
    Code:
    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.
     
    LucaMs likes this.
  6. LucaMs

    LucaMs Expert Licensed User

    I know, that's why I started the question :D

    ... like you did, @LucaMs " (since you, Erel, just did it in your code above).

    It's a... different situation; I need to do it that way.


    Many thanks, Erel, your code is exactly what I needed.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice