Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Updating Clock at a different rate to program loop-example not working as expected?
#1
Hi All,
I hope this is an easy one for someone to point out my mistake.  However I did find some reference to timer behaviour in windows that was different to Linux, so I tried this in Fedora, but both OSs ran the same.  I found this example (I've modified it for QB64 timer only - didn't work as I expected with 'legacy' timer either).  I expected that the clock would update at a rate of once per second, but that the A would be printed every 6 seconds (due to the sleep). However, if you run it the print A occurs every timer tick.  What am I missing?  Thanks!

Code: (Select All)
$Debug
timerhandle% = _FreeTimer
Timer(timerhandle%) On ' enable timer event trapping
Screen 0
Locate 4, 2 ' set the starting PRINT position
On Timer(timerhandle%, 1) GoSub Clock ' set procedure execution repeat time
Rem Sleep
Do While InKey$ = "": Print "A";: Sleep 6: Loop
Timer Off
System

Clock:
row = CsrLin ' Save current print cursor row.
col = Pos(0) ' Save current print cursor column.
Locate 2, 37: Print Time$; "    "; Date$ ' print current time at top of screen.
Locate row, col ' return to last print cursor position
Return
Reply
#2
Short answer: SLEEP is interrupted by timer events.

This is mentioned in passing in the QB45 manual ("the program will stay suspended until ... an enabled event occurs") but appears to be missing from the QB64PE wiki.

You can use _DELAY instead of SLEEP to achieve what you want (though note _DELAY cannot be interrupted by a keypress like SLEEP can).
Reply




Users browsing this thread: 2 Guest(s)