Editor’s Note: This blog is based on a PTC Mathcad Prime 10 worksheet. Download the accompanying Checkbox worksheet here. If you do not have a Mathcad Prime 10 worksheet viewer, download our free 30-day trial here.
One of the Advanced Controls added starting with PTC Mathcad Prime 10 is the Checkbox control, which returns either a 1 or a 0; on or off. Like other controls, you may insert a Checkbox from the Input/Output tab, in the Controls panel, under Advanced Controls. You can customize your Checkbox through a Script (in Mathcad Prime 10, either VBScript or JScript), its appearance can be changed through its Properties or Script and additional customization can be applied from the Mathcad Formatting tab (for example yellow background, Modern 20 font).
The Checkbox's return value can be customized to return something else besides 1 or 0, if preferred.
There are four events in the default script for Checkbox: Start, Exec, Stop and Click. The Exec Event is where inputs and outputs can be processed, returning the state of the Checkbox.
More information can be accessed from the Mathcad Prime 10 Help Center, also accessible from Mathcad Prime's Resources tab, where you can also find a Checkbox Example that they can directly copy in their worksheets and modify as needed, in addition to the worksheet example that we will discuss for the rest of this article. You may also follow along with this video demonstration for the worksheet example:
In the following, we’ll see a Use Case and Code example:
Assuming we have a factory setting, we want to allocate additional time by implementing a structured maintenance schedule for machine usage. This helps with preserving optimal performance and ensuring long-term operational success, while also securing a sustainable and safe production environment. We may have certain regular maintenance tasks, suck as oil changes, inspections, adjustments, cleaning, or parts replacements in the work process. Since preventative maintenance extends the life span of a machinery, its regularity minimizes costly downtime and ensures a consistent production schedule. Well-maintained machines operate more efficiently, consuming less energy, and ensuring consistent high-quality production. This efficiency translates into cost savings and supports the consistent output of high-quality products, which is essential for customer satisfaction and maintaining a strong reputation.
For each maintenance task, an amount of time can be estimated, allocated and implemented, as in this example:
In Step 1 we insert a Checkbox to provide an option to include maintenance time in the calculation. Use the Right Mouse Button to click and select “Edit”.
In this example, we’ll edit the Script to set the caption on the Checkbox depending on the state of the Checkbox (checked or unchecked).
Let’s see how the script looks. To do this, we must right-click on it and select “Edit”.
We have the condition (if) for the Checkbox to provide a certain text and be applied to the equation in the first case. The else case is that "extra" will not be considered in the equation. The checkbox will also display a different text to display exactly what pressing on it will computationally do.
function CheckBoxEvent_Start(Inputs) {
// This function is executed when the checkbox event starts.
// TODO: Add any initialization code or setup actions here.
// If no code is added, the values may be set from the properties defined elsewhere.
}
function CheckBoxEvent_Exec(Inputs, Outputs) {
// This function is executed whenever the checkbox state changes.
// It handles the logic based on whether the checkbox is checked or not.
if (CheckBox.Check()) {
// If the checkbox is checked, set the output value to 1
Outputs[0].Value = 1;
// Update the checkbox text to indicate that only the initial time is included
CheckBox.Text("Clear this box to include only initial time.");
} else {
// If the checkbox is not checked, set the output value to 0
Outputs[0].Value = 0;
// Update the checkbox text to indicate that maintenance time is included
CheckBox.Text("Check this box to include maintenance time.");
}
}
function CheckBoxEvent_Stop() {
// This function is executed when the checkbox event stops.
// TODO: Add any cleanup code or final actions here.
}
function CheckBox_Click() {
// This function is executed when the checkbox is clicked.
// TODO: Add code to handle actions when the checkbox is clicked.
}
By checking the Checkbox to include maintenance time, we see how the results update throughout the document.
In this case, the estimated time in a month could be of about 2.5 hours, representing the difference between the result displayed when the Checkbox is used, versus when it’s not.
Knowing this, the company and its engineers will know how to adjust their schedule to include the extra time needed for maintenance in their work process.
The left side of the control is hidden, and this can be done from the “Hide Left Side” button in the Controls panel.
In Step 2, we use a Mathcad program that checks the value of a Checkbox (which can be 1 or 2) and uses the appropriate formula.
We have the formula for the second machine, a Checkbox with corresponding messages and the Mathcad program containing if-else statements to return a result based on either the first or the second formula.
Further, we have the Usage Notes for a better understanding and focus on the main concepts.
A Checkbox is a graphical user interface element that allows users to make binary choices, typically represented as checked (selected) or unchecked (unselected).
Checkboxes are used where only one option can be selected at a time.
Checked State: When a checkbox is checked, it usually indicates a positive affirmation, like enabling a feature, or including specific options.
Unchecked State: When a checkbox is unchecked, it generally means the user has not selected the option or the option is disabled.
Default State: Set an appropriate default state based on typical user expectations or actions. Avoid setting checkboxes to a state that may mislead users into making unintended choices.
Checkboxes are used to trigger specific functions or calculations within a worksheet when clicked by the user.
They utilize event-driven programming, where actions defined in event handler functions (e.g., Click event) execute upon control activation.
The Click event is triggered when the checkbox is single-clicked. In the Exec event handler, you typically query the Check property to determine the state of the Checkbox.
The Check State Property - Sets or gets a value that determines the checked state of the Checkbox. The Check property of the Checkbox is commonly queried after the Click event.
Maintain consistent styling (formatting properties) to provide a clear and user-friendly interface.
The LeftText property controls the positions of the checkbox and caption text. The Text property sets or gets the caption of the Checkbox. Can be set via the Properties tab or dynamically at run-time.
Provide immediate visual feedback when the checkbox state changes.
Understanding and utilizing these properties, methods, and events can significantly enhance the functionality and interactivity of Checkboxes in Mathcad Prime. The formatting properties allow users to control the appearance of Checkboxes, while the state properties provide information about the current state of each control.
By following these usage notes, you can create intuitive and user-friendly worksheets that use checkboxes for user input and interaction.
For more details, refer to Advanced Control Checkbox Class.
If you’re interested in learning more about the Advanced Control Checkbox Class, Checkbox Events, Checkbox Format Properties and Checkbox State Properties, then you may consult the Help documentation provided online and also inside the software.
Learn more about use cases for all of the Advanced Controls by attending our free, on-demand training event: the Advanced Controls Crash Course!