B4A Class MultiTimer Snippet

If you need a timer that ticks by two or three different intervals, one after the other, here it is, with DblTimer and TriTimer classes.
Edit: This solution is so dumb I wonder why nobody had anything to say about it, guess I'm too respected here...
Edit: I see now that this trick is in Erel's post here https://www.b4x.com/android/forum/threads/iot-traffic-light-with-raspberry-pi.57889/...
The following snippet does it for any combination of intervals and number of intervals:
B4X:
Sub Process_Globals
....
    Private start As Long
    Private lst As List
    Private count As Int = 0
    Private timer1  As Timer
End Sub

Sub AppStart ' or Activity_Create
   lst.Initialize
   lst.Add(1000)
   lst.Add(2000)
   lst.Add(5000)
   timer1.Initialize("timer1",1000)
   timer1.Enabled = True
   start = DateTime.Now
end sub

Sub timer1_Tick
   Dim hit As Int = (DateTime.Now - start)/DateTime.TicksPerSecond
   Log( hit)
   count = (count + 1) mod lst.size
   timer1.Interval = lst.Get(count)
End Sub

Program started.
1
3
8
9
 
Last edited:

derez

Expert
Licensed User
Longtime User
Changed to a snippet with much simpler solution !, see first post.
 
Top