DoEvents and events

WizardOz

Member
Licensed User
Longtime User
Hi!

As I am not at my trusted computer at the moment, I was hoping to get an answer from the guru's of B4A.

I am wondering if DoEvent makes events in the same Activity happen.
Let me show with some pseudo-code:

B4X:
Sub A
   For t = 1 to 100000
      DoEvents
      SomeSearchThingThatDoesntMindbeingDisturbed
    next
End sub

Button_click
   DoSomethingToAnVariable
end sub

Now, my question once again;
Will the Loop stop when Button_click is being clicked beacuse the DoEvents let it happen?
If so, will the loop resume when Button_click is finnished with its purpose?
 

stevel05

Expert
Licensed User
Longtime User
I'm sure that you've seen from the forum that DoEvents within large loops should be avoided if possible. You should really use a timer to achieve what you want.

B4X:
Sub Process Globals
    Dim Timer1 As Timer
End Sub

Sub Globals
    Dim t As Int
End Sub

Sub Activity_Start(First_Time As Boolean)
    t=0
    Timer1.Initialize("Timer1",20)
    Timer1.Enabled=True
End Sub

Sub Timer1_Tick
    t=t+1
    SomeSearchThingThatDoesntMindbeingDisturbed
    If t >= 100000 Then Timer1.Enabled=False
End Sub

Sub Button_Click
     DoSomethingToAnVariable
End Sub

Then the next Timer_Tick sub will be run as soon as possible after the scheduled time and if the click event is called, after the code in the click event has been processed.

Hope this helps
 
Upvote 0

WizardOz

Member
Licensed User
Longtime User
Thanx for the reply Stevel05!

I know about the DoEvents" in large loops are troublesome, but I really wanted to know about what it allowed. :eek:

But your example is a good one, nonetheless! :sign0098:
 
Upvote 0
Top