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
I also see use of
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?
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.
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.
Latest update on this issue. Though putting Me.SetFocus at the top of the WebButton Action code helped, it didn’t give me 100% certainty that all LostFocus code would execute on other WebTextFields fully before the Action code of the WebButton started. Even copying all calcs that those LostFocus events have into the WebButton Action code didn’t help fully. What finally helped with certainty was converting the WebButton to a ReadOnly WebTextField with the action code placed in its MouseDown event (and copying all the LostFocus calcs into that MouseDown event).
Oops. I didn’t describe this quite right. What worked was leaving the WebButton alone and adding a new ReadOnly WebTextField that does the calcs mentioned above and then exposes the WebButton. This way I know that all LostFocus events execute, and calcs are performed before the user can press the WebButton.