Controls > Advanced Controls > Events for Scriptable Controls > Events for Scriptable Controls
Events for Scriptable Controls
The advanced scriptable controls use an event-driven model. The model defines three basic events:
Start
Exec
Stop
Use the Start event to set the properties that need to be set only once for the control. The Exec event and the other control-specific events are used to set properties that are needed for interactions with the control, and for creating outputs.
The events are triggered by Mathcad as the worksheet is recalculated, when internal scripted conditions have been met (such as when data is received back from an external application), or when you click or push a button.
All the events run when:
Applying a new script.
Opening the worksheet when Run Advanced Control script on worksheet open is selected.
Recalculating the worksheet when Run Advanced Control script on worksheet recalculate is selected.
Enabling a region when Auto Calculation is selected.
When a pending region becomes synchronized (selecting Calculate Now, Calculate Worksheet, or Auto Calculate.
The Start, Exec and Stop events run on any interaction with the control or when inputs were changed, even if the Run Advanced Control script on worksheet open or Run Advanced Control script on worksheet recalculate options are off.
In addition, you can use the events defined for advanced controls: buttons, radio buttons, list boxes, checkboxes, text boxes and sliders. Scripts that are defined outside the Start, Exec, and Stop events run when:
Applying a new script.
The first recalculation of the worksheet when Run Advanced Control script on worksheet recalculate is selected.
Changing inputs for the first time, even when the Run Advanced Control script on worksheet open or Run Advanced Control script on worksheet recalculate options are off.
All the events do not run when you copy and paste a control, until the paste is complete, then that script runs as described above.
Syntax in VBScript, JScript and Python
The event function syntax is language-specific. Most scripting languages provide a standard mechanism for event functions, usually a combination of the object which defines the event ("sources" the event) and the name of the event. VBScript, for example, uses the name of the event source, followed by an underscore, followed by the event name.
Sub MyEventSrc_Event1()
'add your code here
End Sub
JScript event handlers are case sensitive, whereas VBScript's are not. JScript's event mechanism specifies the event by the object name followed by an underscore (_) followed by the event name.
function MyEventSrc_Event1()
{
// add your code here
}
Python events are also specified by an object name followed by an underscore.
def MyEventScr_Event1():
#TODO: Add your code here
Was this helpful?