Engineering design calculations must be accurate and error free. When performing calculations in Mathcad, it is always helpful to add color to the worksheet to visually identify critical design parameters, equations, and results. Math regions containing such variables and results can easily be highlighted by accessing the properties panel for the region and enabling the Highlight Region option on the Display tab.
To take the concept of color one step further, consider the benefits of being able to color code a critical result according to whether or not it passes some error check criteria. The ability to “red flag” a result if it does not satisfy design requirements at the time the error is made could conceivably eliminate many mistakes from moving forward undetected. Mathcad’s Scriptable Text Boxes make it possible to incorporate error checking into the calculation process. Intermediate checks can be implemented throughout the worksheet and critical results can be validated before they are used in the next phase of development.
Adding a Scriptable Text Box to a Mathcad Worksheet
- From the Insert menu, select InsertàControlàTextbox.
- Enter a dummy variable into the variable placeholder (this is used for counting purposes). Right-click the textbox and select Add Input Variable. Enter a variable from the Mathcad file whose value will be checked.
In this case, y is a result from the Mathcad file that will be validated to make sure it is not out of range, and count is the dummy variable.
- Right-click the textbox and select Edit Script. Mathcad will open a scripting window with the framework already in place. Add code that performs the error check, populates the textbox with the desired text output (for instance, the output could simply repost the input which in this case would be the value of y, or the output could be a string that communicates status such as Pass/Fail), and sets the background color—this is the important part!
- Save and Close the scripting window.
- Modify variables in the worksheet that will cause the error checking to pass/fail. Observe the textbox change colors to reflect the error checking logic.
The example script below will set the background color of the textbox to red if the input variable has a value greater than one hundred. Similarly, it will set the background color to blue if the value of the input is less than or equal to one hundred. It also sets the output of the textbox equal to the input. Note that the background color should be set in hexadecimal format.
The example script above produces the following color coded result in a Mathcad worksheet where the y variable being checked satisfies the design constraints:
When y is not within the design constraints (i.e. over 100), the example script produces a red background:

Was this tip helpful? Let us know.