Welcome Guest. Please Login or Register. Apr 1st, 2018, 03:49am
ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018. We apologize Conforums does not have any export functions to migrate data. Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.
Thank you Conforums members.
Speed up Liberty BASIC programs by up to ten times!
Compile Liberty BASIC programs to compact, standalone executables!
Overcome many of Liberty BASIC's bugs and limitations!
Using TIMER with a SUB handler
« Thread started 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.
Re: Using TIMER with a SUB handler
« Reply #1 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.