Mathsoft Controls |
Controls, such as list boxes, sliders, and buttons, allow you or other users of your Mathcad documents to enter information other than by defining a variable. This is particularly useful if the end user is new to Mathcad or if you want to streamline a repetitious process. A set of controls allows you to identify and quickly specify control parameters in a calculation and, in some cases, limit the available input choices.
There are six types of controls:
You can create a control in your worksheet by choosing Controls from the Insert menu, or by using the Controls toolbar. You must create a control in a blank area of the worksheet before assigning its output to a variable value. The definition equals sign appears automatically as part of the control.
Some controls can be used with little or no modification, such as a simple push button that assigns a value of 1 or 0 to whatever variable name you choose. Others require additional scripting to be useful. All controls have scripts written in VBScript as a default. These scripts can be modified by right-clicking on the control and choosing Edit Script. If you wish you can use the Scriptable Object component with a Mathsoft control from the object list to script in JScript.
Properties and methods of the control having to do with values and items held by the control are accessible through the script. Controls can also be exported for reuse in other worksheets.
These are the class definitions for the four control types:
The default setting for all controls is one output and no inputs, that is, the control only responds to value changes to itself, not to any worksheet variables. You can modify the number of inputs and outputs, limited only by your system resources. For example, if you wish to use a Mathcad variable value as an input to a script, right-click on the control and choose Add Input Variable. A placeholder will appear below the control, into which you can enter any valid Mathcad supported data type including numbers, arrays, and strings, or any expression that produces one of these values.
Within the script, in the Exec event, values from these placeholders are addressed as Inputs(0).Value and Outputs(0).Value. Indexing of input and output variables starts at 0. Inputs and Outputs are members of DataValue collections, with associated properties and methods. Using outputs of one control as inputs to another, you can include multiple controls in the same worksheet.
You can also get and set values in the worksheet by using Mathcad's Automation commands in the script if you need to manipulate these values in event handlers other than the Exec event. You should still set input and output values when you use the Automation commands. By associating a component or control with input and output values, you define its place in the calculation order of the worksheet, and notify it to recalculate when input values change, as well as notify the worksheet when to update the output values. It is therefore important that you assign input and output values to any component that will use these worksheet variables, even if you access the value of the variable through Mathcad's Automation interface using GetValue or SetValue methods.
Finally, note that there is a general Recalculate method which can be called inside any event handler in a script, causing the component to recalculate the region.
Properties and methods of each control having to do with display (font, alignment, images, and so on) are modified through the Properties dialog. Right-click on a control and choose Properties to see the available options for a particular control.
In order to hide control arguments from end users, right-click the control and select Hide Arguments. To reveal the arguments, right-click the control again and select Show Arguments.
As a safeguard against potentially destructive code, Mathcad issues a warning message every time you attempt to open a worksheet that contains scripted objects. If you are opening a worksheet containing scripted objects that you know to be safe, such as the sample files that demonstrate these controls, click "No" when the warning box comes up. Doing so enables all the scripted objects in the worksheet. If you answer "Yes" and still want to enable these components in the worksheet, either right-click a single control and select Enable Evaluation, or select one or more controls, right-click and select Properties from the menu. In the Properties dialog on the Calculation tab, uncheck Disable Evaluation.
Here are a few examples of how controls might be used:
Example worksheets contained in the \qsheet\samples\controls folder of your installation of Mathcad illustrate how to use the controls in a variety of ways. These files are listed in QuickSheets, under the Programming section.