Sub Sleep(ms As Long)
Dim now As Long
If ms > 1000 Then ms =1000 'avoid application not responding error
now=DateTime.Now
Do Until (DateTime.Now>now+ms)
DoEvents
Loop
End Sub
Dim Timer1 as Timer( in Process Globals)
Timer1.Intitialize("Pause",2500)
Timer1.Enabled=True
Sub Pause_Tick
Timer1.Enabled=False
'Now continue to another sub...As far as I know, it is not possible to return to a label in B4A..yet)
End Sub
Timer1.Initialize("Timer1", 1000) ' 1000 = 1 second
Timer1.Interval = Rnd(46000,88000)
The while loop crushes the battery and makes the app go ANR. You don't want to use it for pauses, ever.
Use the code from cableguy above. Variable passed is in MilliSeconds, so 5000 is 5 seconds, 10000 is 10 seconds etc.
in Process_Globals
Dim Timer1 As Timer
Split your current sub
Sub FirstHalf
do stuff
Timer1.Intitialize("Pause",2500) '2.5 seconds
Timer1.Enabled=True
end sub
sub SecondHalf
do more stuff
end sub
Sub Pause_Tick
Timer1.Enabled=False
SecondHalf
End Sub
Sub FirstHalf()
dostuff with i
set your timer
end sub
Sub SecondHalf()
domorestuff with i
If i <200 then
i = i + 1
FirstHalf
end if
end sub
Sub FirstHalf()
dostuff with i
Timer1.Intitialize("Pause",2500) '2.5 seconds
Timer1.Enabled=True
end sub
Sub Pause_Tick
Timer1.Enabled=False
If i <200 then
i = i + 1
FirstHalf
end if
End Sub
Sub Wait(Sekunden As Int) works very good, but the minimum wait time is 1 second. Is there a way to pause for a fracture of a second?
Thank you all
Sub Wait(MilliSekunden As Int)
Dim Ti As Long
Ti = DateTime.Now + MilliSekunden
Do While DateTime.Now < Ti
DoEvents
Loop
End Sub
One second is 1000 milliseconds. Here the sub based on milliseconds.
B4X:Sub Wait(MilliSekunden As Int) Dim Ti As Long Ti = DateTime.Now + MilliSekunden Do While DateTime.Now < Ti DoEvents Loop End Sub