59
Event trapping could be nested. If the event triggers are activated in a BASIC program, it
is possible that an event-driven subroutine can be interrupted by any upcoming events.
Normally, the new event would be processed first.
In some cases where we don’t want the event-driven subroutine to be interrupted by
other events, the commands LOCK and UNLOCK can be used to hold off new events.
LOCK
Purpose To hold all the activated event triggers until they are released by UNLOCK.
Syntax LOCK
Remarks This command can prevent nesting of event triggers. All the ac
triggers will be disabled until UNLOCK is called.
In the example below, the BASIC program can trap the READER(1) and
READER(2) events and reroute to the subroutines BcrData_1 and BcrData_2
respectively. In BcrData_1, the command LOCK disables
all the activated event
triggers so that the subroutine BcrData_1 will not be interrupted by a new
upcoming READER(1) and/or READER(2) event. On the other hand, since LOCK
is not called in BcrData_2, any new coming READER(1) and READER(2) event
will inter
rupt the ongoing BcrData_2, and therefore, may affect the expected
results.
Example
ON READER(1) GOSUB BcrData_1
ON READER(2) GOSUB BcrData_2
…
BcrData_1:
LOCK
BEEP(2000, 5)
Data$ = GET_READER_DATA$(1)
GOSUB AddNewData
UNLOCK
RETURN
…
BcrData_2:
BEEP(2000, 5)
Data$ = GET_READER_DATA$(2)
GOSUB AddNewData