HTBasic Help
×
Menu
Index

ON EVENT

Defines an event branch to take after a widget generates that event
 

Example

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
ON EVENT @Main,"SYSTEM CLOSE" GOTO Finis
 

Syntax

 
ON EVENT @w_hndl, event_name [, priority] { { GOTO | GOSUB | RECOVER } line_ref | CALL sub_name }
 
Item
Description
Range
event_name
name of an event this widget can generate
depends on the widget
line_ref
line label or a program line number
to 32767 or line label
priority
numeric expression,, rounded to an INTEGER. Default = 1.
to 15 (highest)
sub_name
name of a SUB or CSUB subprogram
any valid name
w_hndl
widget handle name
any valid name
 

Description

ON EVENT enables the event and sets up the branch to take when the specified widget generates an event.
 
For example:
 
ON EVENT @Slider;"CHANGED" GOSUB Event_handler
 
The most recent ON EVENT (or OFF EVENT) for a given widget and event combination overrides any previous definition for that combination. If the overriding ON EVENT definition occurs in a different context from the overridden one, 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) contextat 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. For example:
 
VAL(SYSTEM$("SYSTEM PRIORITY"))+1 !will cause an error if current system priority is 15
 
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. It is reenabled by ENABLE EVENT or ENABLE, and is deactivated by OFF EVENT.