LB Booster
Programming >> Language extensions >> Using TIMER with a SUB handler
http://lbb.conforums.com/index.cgi?board=extensions&action=display&num=1427480552

Using TIMER with a SUB handler
Post by Richard Russell on Mar 27th, 2015, 6:22pm

There's currently a thread at the LB Community Forum with the subject 'timer 0' not working which describes a problem arising from the use of the TIMER statement. In LB 4.04 the only kind of timer handler you are allowed is a [label], which means that if the timer fires when the label is 'out of scope' (typically when a SCAN or WAIT is executed inside a SUB or FUNCTION) a run-time error will result.

As the OP found, this issue can be difficult to work around; he resorted to disabling the timer with TIMER 0 before calling the subroutine and re-enabling it afterwards, but still experienced problems. One of the responses posted there was "I personally do not use the Timer function in LB as it seems to cause more issues than I care for".

In LBB you can alternatively specify a SUB as the handler in the TIMER statement (if you try that in LB4 it crashes). The potential advantage of using a SUB handler is that it is always in scope, so whether the timer fires in the 'main program' or when inside a function it should always work correctly.

Richard.
Re: Using TIMER with a SUB handler
Post by CryptoMan on Mar 28th, 2015, 10:54pm

In Unix with C we were using SETJMP and LNGJMP for this with ALARM function to fire a timer alarm and then jump to function from wherever we are and then after handling whatever necessary we made a long jump back into the where this timer event was triggered.

So, effectively LBB is able to this powerful thing.

Would it be possible to handle multiple timers?

Can we trap and handle other signals?
Re: Using TIMER with a SUB handler
Post by Richard Russell on Mar 28th, 2015, 11:12pm

on Mar 28th, 2015, 10:54pm, CryptoMan wrote:
Would it be possible to handle multiple timers?

This LB demo of multiple timers works fine in LBB too:

http://lbpe.wikispaces.com/MultipleTimerRoutines

Richard.