HTBasic Help
×
Menu
Index

ON EVENT

Defines an event branch for a Widget generated event.
 
 ON EVENT
                              
Where:
action = { GOTO|GOSUB|RECOVER } line | CALL subprogram
line = line-number | line-label
 
Usage:
ON EVENT @Pushbutton_3,"ACTIVATED" GOSUB Clear_profile
ON EVENT @Slider, "DONE" GOSUB Change_temphigh
ON EVENT @Sldr,"CHANGED", VAL(SYSTEM$("SYSTEM PRIORITY"))+1 GOSUB Chg_stpnt
 
Description:
ON EVENT defines the event branch and enables the event.
 
The most recent ON EVENT (or OFF EVENT) statement for a given widget and event combination overrides any previous ON EVENT definition for that combination. If the overriding ON EVENT definition occurs in a context different from the one in which the overridden ON EVENT occurs, the overridden ON EVENT is restored when the calling context is restored.
 
Any specified line reference for GOTO or GOSUB must be in the same context as the ON EVENT statement. CALL and GOSUB will return to the next line that would have been executed if the ON EVENT widget event had not been serviced. The system priority is restored to that which existed before the ON EVENT branch was taken.
 
RECOVER forces the program to go directly to the specified line in the context containing that ON EVENT statement. When RECOVER forces a change of context, the system priority is restored to that which existed in the original (defining) context at the time that context was exited.
 
NOTE
The priority specified in the ON EVENT statement (as in all ON-event statements) must be higher than the current system priority in order for the event to be recognized.
 
When you nest ON EVENT statements, be aware that the system priority is raised to the one you specified in the ON EVENT statement, when that event is serviced for CALL and GOSUB.
 
To ensure that the events are recognized for all of your ON EVENT statements, specify a higher priority each time you go deeper into the nesting. To do this, query for the current system priority and then increase it by one, instead of specifying the priority as a number between the event name and GOTO, GOSUB, RECOVER, or CALL.
 
Use the following command sequence within the ON EVENT statement
to do this. (This technique will cause an error if the current system priority is 15.)
 
    VAL(SYSTEM$("SYSTEM PRIORITY"))+1
 
CALL and RECOVER remain active when the context changes to a subprogram or function, unless the change in context is caused by a keyboard-originated call. GOSUB and GOTO remain active when the context changes to a subprogram, but the branch cannot be taken until the calling context is restored.
 
ON EVENT is disabled by DISABLE EVENT or DISABLE, is re-enabled
by ENABLE EVENT or ENABLE, and is deactivated by OFF EVENT.
See Also: