Delaying PushButton code until . . .

  1. 2 weeks ago

    Ralph A

    Nov 29 Santa Monica, California

    I think I tracked down a problem in my Web app, and think that it arises when code in a PushButton's Action event executes too soon. I need it to execute after the LostFocus event of a field executes completely. The PushButton seems to work if the user clicks out of the field in question and then clicks the PushButton. The problem seems to occasionally arise if they click the PushButton immediately after changing data in the field in question.

    In this forum I have found this, but with a warning that it's not good to use in modern day UI code:

    // do nothing for 1/4 second or so
    Dim waitUntil As Integer = Ticks + 15
    While ticks < waitUntil
    Wend

    I also see use of

    app.SleepCurrentThread(250)

    to accomplish something similar. But won't the SleepCurrentThread code interfere with the LostFocus event I'm talking about? That is, wouldn't it halt all code execution in that thread, thusly working against what I'm trying to do?

    Would a WebTimer with a Period of 250 (placed at the beginning of the PushButton Action event) accomplish what I'm trying to do and be more fitting with modern UI programming?

    Seems that putting Me.SetFocus at the top of the WebButton code works.

  2. Greg O

    Nov 29 Xojo Inc

    Neither of those will work on the web because events are fired asynchronously in the web.

    What is it that you are doing in lostFocus?

  3. Ralph A

    Nov 29 Santa Monica, California

    The LostFocus event rounds the entered number and then totals all 7 fields in that row and inserts that value in the 8th column of that row. It also totals the 6 fields in the column where the number was entered and enters that value in the bottom field in that column (7th row). And all the fields in the 8th column are totaled and that value is placed in the bottom field of the 8th column (7th row). In other words, a lot of totaling of fields.

    I also seem to remember noticing, in a different Web app, that a WebButton press wasn't seen as a New Focus, and so I couldn't rely on a LostFocus event in another control getting reliably fired when pressing a WebButton. Not sure about this.

  4. Ralph A

    Nov 29 Santa Monica, California
    Edited 2 weeks ago

    And if the user touches somewhere else in the layout, before pressing the WebButton, letting the LostFocus event fire, the WebButton exhibits no problems as far as I can tell. The WebButton event uses values found in the 8th column.

  5. Greg O

    Nov 29 Xojo Inc
    Edited last week

    How about doing that calculation at the top of the pushbutton code as well?

  6. Ralph A

    Nov 29 Santa Monica, California

    @Greg OLone How about doing that calculation at the top of the punch button code as well?

    This makes sense. I'll try it. It should work.

  7. last week

    Ralph A

    Nov 30 Answer Santa Monica, California

    Seems that putting Me.SetFocus at the top of the WebButton code works.

or Sign Up to reply!