Vipul Trivedi is a Solution Consultant for PTC Mathcad Prime. He is proud of the innovation and creativity his work showcases, excelling in high-level design software like Mathcad Prime and Creo Parametric. Apart from his work, Vipul also enjoys extracurricular adventures. A lover of outdoor sports, he finds joy in the thrill of physical activities that complement his cerebral pursuits.
Editor’s Note: This blog is based on PTC Mathcad Prime 11 worksheets. If you do not have a Mathcad Prime 11 worksheet viewer, download our free 30-day trial here.
Starting with PTC Mathcad Prime 10, you can insert advanced scriptable control structures in your worksheet, unlocking new possibilities for productivity and automation. The six types of advanced controls are buttons, checkboxes, list boxes, radio buttons, text boxes, and sliders. You can write your scripts in JScript, Python (starting in Mathcad Prime 11), and VBScript. Note that Microsoft has announced that VBScript will no longer be available by default on Windows computers by 2026 or 2027, so PTC strongly recommends writing your scripts in JScript or Python. Python is available as a separate installation, and Mathcad Prime supports Python 3.7 to Python 3.13.
Button advanced control
How to add triggerable events with Button advanced controls
The Button scriptable control in PTC Mathcad Prime is a powerful tool for capturing user input through button selection and de-selection. While push buttons typically return a binary value of 1 or 0 (on or off), their behavior can be significantly enhanced through scripting, utilizing the Button class and other scripting language features. This section explores the sophisticated capabilities of the Button control, its customization options, and the event-driven programming model that underpins its functionality.
Inserting & event-driven programming with the Button control
Creating a Button control
To create a push button control in Mathcad Prime:
- Navigate to the "Input/Output" tab’s "Controls" section
- Select "Button" and place it in your worksheet where you want the options to appear.
Default script of Buttons
The default script for a Button control includes four key events: Start, Exec, Stop, and Click. Each of these events serves a specific purpose in the button’s lifecycle and interaction model:
- Start: This event is ideal for initializing the button and setting its formatting properties. It runs when the script is first executed and sets up the initial state of the button.
- Exec: In this event, inputs and outputs are processed, including returning the state of the button. It handles the core logic of the button’s functionality.
- Stop: This event is used for cleanup and finalization tasks when the script is terminated.
- Click: The most crucial event for push buttons, the Click event handles state changes and re-executes the control after the user interaction. This is where the button's logic responds to user input, ensuring that the appropriate actions are taken based on the button's new state.
By default, push buttons provide basic functionality, but behavior can be extensively customized:
- Naming Convention: The button’s text (name) can be altered by right clicking the button and selecting Edit > Properties. Alternatively, formatting properties can be set through scripting, offering greater flexibility and control. Note that settings applied via the script will override those made in the Properties dialog.
- Dual-State Appearance: While the Properties tab allows changes to a single state setting, scripting is required to program appearance effects for both states of the button. This enables dynamic visual feedback based on the button’s state.
Button use case & code example
In this example, we have a Mathcad Prime worksheet featuring three push buttons, each designed to perform a specific task. You can read along the explanations below, and/or watch the embedded video about this same worksheet to follow along. Note that since the video was produced, Button 1 has been edited to allow the user to input the location of the web content they would like to copy with a Text Box control, as opposed to the original functionality where the URL was hard-coded into the Button's Script Editor.
All example worksheets throughout this blog can be found as either JScript or Python worksheets.
Download the accompanying worksheet here.
Download the worksheet in either JScript or Python to follow along and explore the Button control.
Download HereStep 1: Web content to Word using button
In this Mathcad Prime worksheet, a button labeled Open Word has been created to automate content management tasks. When clicked, this button performs the following actions:
- Copy Content from Web Page:- The button initiates a script that accesses a predefined web page, copies its entire content, and prepares it for transfer.
- Open Word and Paste Content:- The script then opens a new Microsoft Word document and pastes the copied content into it, ensuring a seamless transfer of information from the web to Word.
- Close Word Option:- The same button provides an additional option to close the Word document, allowing users to manage the document lifecycle efficiently from within the Mathcad Prime environment.
This feature is particularly useful for users who need to integrate web-based data into their reports or documentation, streamlining the workflow by combining multiple steps into a single, user-friendly interface. For integrating or automating tasks within Mathcad Prime ActiveXObject is utilized in below button script.
Step 2: Recalculate worksheet button
The button labeled "Recalculate" has been implemented to streamline the process of updating all calculations. When clicked, this button triggers the recalculation of the entire worksheet, ensuring that all formulas, data inputs, and results are refreshed and up to date. This feature is particularly useful after making changes to input values or modifying equations, as it guarantees that all dependent computations are accurately recalibrated, maintaining the integrity and consistency of the analysis. The "Recalculate" button enhances efficiency and user experience by providing a quick and convenient method to update the worksheet without manually recalculating each element.
Step 3: Save worksheet button
The Button labeled "Save" has been added to facilitate the saving process. When clicked, this button automatically saves the current state of the worksheet, ensuring that all recent changes, calculations, and data entries are securely stored. This feature is designed to enhance user efficiency by providing a quick and reliable method to save progress without navigating through menus. The "Save" button is particularly useful during extensive data analysis or iterative calculations, as it allows for frequent saves, minimizing the risk of data loss and maintaining the integrity of ongoing work.
Benefits of using push buttons
- Simplicity and Clarity: Automating repetitive tasks with push buttons saves time and effort, allowing users to focus on more critical aspects of their work.
- Streamlined Workflow: Push buttons make Mathcad worksheets more interactive and user-friendly, improving the overall user experience.
- Dynamic Interactivity: Automation reduces the risk of human error, ensuring that tasks are performed accurately and consistently.
- Customization: Push buttons facilitate seamless integration with external applications (Microsoft Word in this case), extending the functionality of Mathcad worksheets.
Push button conclusions
Push buttons are powerful tools that enhance the interactivity, efficiency, and functionality of worksheets. By automating tasks such as web content copying, worksheet recalculation, and saving, push buttons enable users to streamline their workflow and improve productivity. The practical application of these push buttons in a Mathcad worksheet demonstrates their versatility and utility in real-world scenarios.
Incorporating push buttons into your Mathcad Prime worksheets can transform the way you work, making complex tasks simpler and more efficient. Whether you are automating web content transfers, recalculating worksheets, or saving your progress, push buttons provide a powerful solution to enhance your productivity and accuracy.
If you’re interested in learning more about the Advanced Control Button Class, Button Format Properties, Button Events, and Examples, then you may consult the Help documentation provided online and also inside the software.
Check Box advanced control
How to set binary options with Check Box advanced controls
Don’t forget to download the accompanying Mathcad Prime worksheet for the Check Box example below.
Download the accompanying Checkbox worksheet here.
Download the worksheet to follow along on your own and explore the Checkbox capabilities.
Download HereAbout the Checkbox
One of the Advanced Controls is the Check Box 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 Check Box through a script, 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 Check Box'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 Check Box: Start, Exec, Stop, and Click. The Exec Event is where inputs and outputs can be processed, returning the state of the Check Box.
For more information on the Check Box Advanced Control, visit the Mathcad Prime help center, which is accessible from Mathcad Prime’s Resources tab. From here you can also find the example discussed below.
Check Box use case & code example
Read the explanations below and/or watch the embedded video to follow along with the Check Box example.
In a factory setting, allocating additional time by implementing a structured maintenance schedule for machine usage is critical for preserving optimal performance and ensuring long-term operational success, while also securing a sustainable and safe production environment.
Regular maintenance tasks, such as oil changes, inspections and adjustments, cleaning, and parts replacement play a crucial role in this process. Preventative maintenance extends the lifespan of machinery, reducing wear and tear and avoiding unexpected breakdowns. This 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, a certain time can be estimated, as in the example below. The estimated exceeding time in a month could be 3 hours. Knowing this, the company and its engineers will know how to adjust their working schedule to include this extra time in their work process.
Step 1
Insert a Check Box 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 Jscript to set the caption on the Check Box depending on the state of the Check Box (checked or unchecked).
Step 2
Use a Mathcad program that checks the value of the Check Box (1 or 2) and uses the appropriate formula.
Check Box usage notes
- Definition & Purpose: A Check Box is a graphical user interface element that allows users to make binary choices, typically represented as checked (selected) or unchecked (unselected). Check Boxes are used where only one option can be selected at a time.
- Checked State: When a check box is checked, it usually indicates a positive affirmation, like enabling a feature, or including specific options.
- Unchecked State: When a check box 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 check boxes to a state that may mislead users into making unintended choices.
- Function Triggering & Event Handling: Check Boxes 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 check box is single-clicked. In the Exec event handler, you typically query the Check property to determine the state of the Check Box. The Check State Property - Sets or gets a value that determines the checked state of the Check Box. The Check property of the Check Box is commonly queried after the Click event.
- Consistency: Maintain consistent styling (formatting properties) to provide a clear and user-friendly interface. The LeftText property controls the positions of the check box and caption text. The Text property sets or gets the caption of the Check Box. Can be set via the Properties tab or dynamically at run-time.
- Feedback: Provide immediate visual feedback when the check box state changes.
Understanding and utilizing these properties, methods, and events can significantly enhance the functionality and interactivity of Check Boxes in Mathcad Prime. The formatting properties allow users to control the appearance of Check boxes, 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 Check Box Class.
List Box advanced control
How to dynamically populate value options with List Box advanced controls
In engineering and scientific calculations, providing users with an intuitive and interactive way to select input parameters is crucial for enhancing productivity and accuracy. Mathcad Prime offers a list box along with other advanced control features to facilitate this. However, many users may not be fully aware of how to effectively implement and utilize list boxes to dynamically update calculations and enhance the user experience in their worksheets. This section aims to address this gap by detailing the creation, configuration, and application of list boxes in Mathcad Prime, demonstrating their benefits in practical scenarios, and providing step-by-step guidance to leverage this tool for more efficient and error-free data input.
Explanation of List Box in Mathcad Prime
Purpose and usage
The List box in Mathcad Prime is used to:
- Provide a selection of options that users can choose from.
- Dynamically change the content or calculations in a worksheet based on user input.
- Enhance the interactivity and usability of Mathcad worksheets.
Creating a List Box
- Insert the List Box:
- Navigate to the "Input/Output" tab “Controls” section
- Select the "List Box" control from the available options.
- Define List Items:
- After inserting the list box, you can define the list of items that will appear in the box.
- This is usually done by specifying a range or an array of items.
- Linking to Variables:
- The selection made in the list box can be linked to a variable in the worksheet.
- This variable can then be used in further calculations or to dynamically change the content of the worksheet.
Default Script of List Box
The default script for a list box in Mathcad Prime defines several key components and events that manage the list box's behavior. Here is a detailed explanation of the script, including the major events:
- Initialization Section:
- ListBox.ResetContent(): Clears any existing items in the list box.
- ListBox.AddString("One");
- ListBox.AddString("Two");
- ListBox.AddString("Three");
- Adds three items ("One", "Two", "Three") to the list box.
- ListBox.CurSel(0): Sets the default selected item to the first item in the list ("One"), as the index is zero-based.
- ListBoxEvent_Start:
- This function is called when the list box event starts.
- Typically used for any initialization that needs to occur when the list box becomes active.
- Currently, it contains a placeholder comment indicating where the user can add custom initialization code.
- ListBoxEvent_Exec:
- This function is executed to process the current state of the list box.
- ListBox.CurSel() returns the index of the currently selected item.
- Outputs[0].Value = ListBox.CurSel() + 1; sets the output value to the index of the selected item plus one (converting from zero-based to one-based indexing).
- ListBoxEvent_Stop:
- This function is called when the list box event stops.
- Typically used for cleanup or finalization tasks.
- Contains a placeholder comment for user-defined code.
- ListBox_SelChanged:
- This function is called when the selection in the list box changes.
- It can be used to handle any actions or updates needed when a new item is selected.
- Currently contains a placeholder comment for custom code.
- ListBox_DblClick
- This function is triggered when an item in the list box is double-clicked.
- It can be used to define specific actions that should occur on a double-click event.
- Contains a placeholder comment for user-defined code.
- Intuitive Interface
- List boxes provide a straightforward and user-friendly way for users to select from a predefined set of options. This simplicity makes them easy to understand and operate, even for users with limited technical expertise.
- Minimal Input Errors
- By restricting input to a set of predefined options, list boxes significantly reduce the risk of user input errors compared to text fields or other free-form input methods.
- Dynamic Updates
- List boxes can be dynamically updated based on user selections. For example, selecting a crude oil type can automatically populate the by-products list box, ensuring relevant and context-specific options are always available.
- Event Handling
- List boxes support event handling for selection changes, double-clicks, and other interactions. This allows for real-time updates and calculations, enhancing the interactivity and responsiveness of the worksheet.
- Quick Selection
- List boxes allow users to quickly select from multiple options without typing, saving time and improving efficiency, especially when dealing with extensive lists of items.
- Clear Options Presentation
- Items in a list box are clearly displayed, making it easy for users to see all available choices at a glance. This is particularly beneficial for presenting categorized or hierarchical data.
- Linked Variables
- Selections in list boxes can be directly linked to variables used in calculations. This seamless integration simplifies the process of using user inputs in computational formulas, ensuring that calculations are always based on the latest selections.
- Automated Updates
- Changes in list box selections can trigger automatic updates in related calculations and outputs, ensuring that the worksheet always reflects the current state of user inputs without requiring manual updates.
- Customizable Options
- List boxes can be easily customized to include any number of options, tailored to the specific needs of the worksheet. This flexibility allows for precise control over the data input process.
- Hierarchical Selection
- When used in conjunction with multiple list boxes, hierarchical selection can be implemented (e.g., choosing a crude oil type, then its by-products leading to selection of flow rate and velocity), making complex data structures manageable and easy to navigate.
- Insert the Radio Button:
- Navigate to the "Input/Output" tab's “Controls” section
- Select "Radio Button" and place it in your worksheet where you want the options to appear.
- Define Options and Groups:
- After inserting, define the different options by adding multiple radio buttons
- Script and Linking to Calculations:
- Link the radio buttons to specific calculations or scripts by accessing the "Properties" tab and specifying the corresponding script or function.
- This allows the selected option to influence the worksheet’s calculations, providing dynamic and interactive content based on user selection.
- Start: Used for initializing and formatting the radio button. You can also define formatting settings in the Properties tab.
- Exec: This is where inputs and outputs are processed. It returns the current state of the radio button, allowing you to handle user selections and update calculations accordingly.
- Stop: Typically used to perform any cleanup operations when the radio button is no longer needed.
- SelectionChange: Triggered whenever the user changes their selection. This event can be used to update related calculations or interface elements dynamically.
- Default Selection
Ensure the default selection is meaningful for the worksheet's context. This helps guide users towards a typical use case and ensures calculations start with valid data. - Conditional Calculations
Use the selected value to conditionally display a certain text. - Consistency, styling and appearance
Customize the appearance of the Text Box to make it more visually appealing and aligned with the worksheet’s design. Formatting properties help maintain consistent styling and spacing for all Text Boxes to provide a clear and user-friendly interface.
BackColor and ForeColor: Sets or gets the background color for the control. The ForeColor property sets or gets the foreground color for the control.
FontSize: Sets or gets the font size of the text displayed in the control's text field. Multiline: Indicates whether a Text Box can have multiple lines of text. When true, use the Enter key to go to the next line. When false, the text will be displayed in a single line and using the Enter key will move the cursor out of the Text Box.
Use Mathcad's Math Formatting to set the preferred font for values entered into the Text Box. - Observability and Controllability
Text: The Text property sets or gets the text of the Text Box. The text is limited to 1000 characters.
ReadOnly: The ReadOnly property sets or gets whether the text is read-only or is editable.
Multi-line Text: In the JScript code, use "\r" to add a new line when setting text inside a Text Box.
Example: TextBox.Text("TextLine One\rTextLine Two") - Integration with Other Controls
Text Box Controls can integrate with other Mathcad Prime controls to create interactive and dynamic worksheets. Use the Text Box in conjunction with other input controls like list boxes, checkboxes, buttons, radio buttons or sliders to create comprehensive interactive worksheets.
Properties of List Boxes
The default script sets up a list box with three items and initializes the first item as selected. It includes placeholders for additional initialization, execution, stopping, selection change, and double-click events, allowing users to customize the behavior of the list box according to their needs.
By adding appropriate code to these placeholders, users can make the list box interact dynamically with other parts of the Mathcad Prime worksheet, responding to user selections and triggering calculations or updates as required.
Download the accompanying List Box worksheet here.
Download the worksheet to follow along on your own and explore the List Box capabilities.
Download HereList Box use case & code example
Follow this example in this embedded video and/or continue reading the descriptions below.
Introduction
Crude oil, a complex mixture of hydrocarbons, is classified into different types based on its geographic origin, chemical composition, and physical properties. Each type of crude oil yields various refined products, ranging from fuel to lubricants, through the refining process. The List Box below contains a list of crude oil based on Geographic Origin.
Problem statement
The determination of the appropriate pipe diameter for transporting specific by-products of crude oil, based on varying flow rates and velocities, is essential for efficient and cost-effective refining operations. This calculation is crucial not only for optimizing the transportation of these by-products but also for accurately estimating the time required to fill a designated volume. By integrating these parameters into our analysis, we can ensure seamless and efficient operations within the petroleum industry.
Step 1
Select a crude oil type from the List Box. Based on your selection, the main by-products of selected crude oil will be populated in the second List Box (Step 2) and update the flow rate and velocity. The list button code initializes a list of crude oil types for selection, updates settings based on the selected option, and outputs the selected item’s index and text.
Step 2
Select one of the following by-products to which diameter needs to be calculated. The List Box code dynamically updates its content based on input selections, displaying relevant options and outputting the selected value and text.
Step 3
Selecting a by-product will update the flow rate and velocity values based on assumed generic values as different by-products have different velocity and flowrate. Both List Boxes below dynamically update their options based on selection of the second List Box. This has been considered to change as the flow rates and velocities differ for different kinds of fluids.
Step 4
Users can add a new volume to the list box by entering a value in a text box and appending a space to confirm the addition. The list of tank volumes is then updated accordingly. This will also check if the number entered is already in the list and then will not add the repeated number.
Step 4.1
Choose the volume of the tank that needs to be filled. Then, using the flow rate equation, you’ll be able to calculate the pipe diameter for the selected by-product.
List Box benefits
Using list boxes in Mathcad Prime offers several distinct benefits over other advanced controls. Here are ten key advantages:
Simplicity and ease of use
Dynamic interactivity
Efficiency in data entry
Integration with calculations
Customization and control
List Box conclusions
By integrating these list boxes and calculations into a Mathcad Prime worksheet, users can interactively select crude oil types, by-products, flow rates, velocities, and tank volumes. This approach ensures accurate and efficient calculations for pipe diameter, area, Reynolds number, and time required for filling tanks. The use of Mathcad Prime’s list boxes not only enhances user experience but also streamlines complex engineering calculations in the petroleum industry.
List boxes in Mathcad Prime offer an ideal balance of simplicity, interactivity, and efficiency, making them a powerful tool for managing user inputs in engineering calculations. Their ability to dynamically update, minimize errors, and integrate seamlessly with worksheet variables makes them superior to other advanced controls for many practical applications.
If you’re interested in learning more about the Advanced Control List Box Class, List Box Events, List Box Format Properties, List Box Methods and List Box State Properties then you may consult the Help documentation provided online and also inside the software.
Radio Button advanced control
How to make dynamic value updates with Radio Button advanced controls
In modern engineering calculations and design workflows, user interface elements play a crucial role in ensuring efficiency, accuracy, and ease of use. One such versatile element is the radio button, which allows users to select one option from a predefined set. This section delves into the application of radio buttons within a Mathcad Prime worksheet, illustrating their uses, benefits, and functionalities through a practical scenario.
Creating a Radio Button
Adding a Radio Button to the worksheet
To create a radio button in Mathcad Prime:
Default script of Radio Buttons
The default radio button script includes four main events:
Properties of Radio Buttons
By understanding and utilizing these events, user can create a highly interactive and user-friendly interface in Mathcad Prime worksheets, ensuring that all user selections are accurately processed and reflected in real-time calculations.
Download the accompanying Radio Button worksheet here.
Download the worksheet to follow along on your own and explore the Radio Button capabilities.
Download HereRadio Button use case & code example
Problem statement
A particular problem in Statics is the solution of a threaded screw. Follow the video above to see the example in a Mathcad Prime worksheet. The basic solution process is to calculate Tangential Force, Torque, thread angle and whether thread is self-locking or not based on varying load, coefficient of friction and selecting Bolt Size:
Step 1
Select one of the following Conditions. Based on the selection, different variables will be populated in the other radio button. The Radio Button code initializes options, updates settings based on the selected option, and sets output values accordingly.
Step 2
Select one of the following variables that needs to be calculated. The radio button dynamically updates its options and appearance based on input values: it sets button labels and orientation based on specific conditions, and outputs the ID of the selected button.
Step 3
Select the type of thread of the bolt. Changing the thread type will update the value of 'lead.' The radio button allows users to select a thread type ("Super Fine," "Fine," or "Course"), and based on the selection, it sets and outputs a corresponding lead value (1.25, 1.50, or 2).
Step 4
Select if the bolt is single, double, or triple thread. Upon selection of the Radio Button, the value of lead will update.. This Radio Button allows users to select between "Single," "Double," or "Triple" options. Based on the selection, it multiplies a given value by the corresponding factor and outputs the result.
The value of lead is influenced by both the type of thread and the type of thread starting chosen. Specifically, the lead value is calculated by multiplying the thread type by the thread starting type. This means that different thread configurations will result in varying lead values. Understanding the relationship between these factors is crucial for accurate thread performance and functionality.
Step 5
Select purpose based upon tightening or loosening the bolt.
Step 6
Use the text box below to Add new a Radio Button value to step 6.1 if you want to choose different diameter apart from what is listed.
Step 6.1
Select the bolt size. The below radio button interface initializes with predefined options ("M10", "M12", "M16") and allows adding a new button based on user input. It then extracts and outputs the numeric part of the selected button's text box. It will also check if the input is already present in radio button.
Radio Button benefits
Simplicity & clarity
Radio buttons offer a clear and straightforward way to present mutually exclusive options, reducing user confusion and errors.
Streamlined workflow
By guiding users through a step-by-step selection process, radio buttons ensure that all necessary inputs are gathered before calculations begin.
Dynamic interactivity
Changes in selections immediately update the results, providing real-time feedback and allowing users to explore different scenarios effortlessly.
Customization
The combination of radio buttons with other elements like sliders and text boxes allows for a highly customizable and user-friendly interface.
Radio Button conclusions
Radio buttons, when used effectively, can significantly enhance the usability of engineering tools in Mathcad Prime. By structuring the user interface to guide inputs and provide dynamic feedback, they make complex calculations more accessible and intuitive. This scenario demonstrates the power of well-designed interactive elements in creating efficient and user-friendly computational tools.
Incorporating radio buttons and other interactive elements in worksheets can transform how users interact with calculations, leading to faster results and a more enjoyable user experience. Try implementing these elements in your next Mathcad Prime project and experience the benefits firsthand!
If you’re interested in learning more about the Advanced Control Radio Button Class, Radio Button Format Properties, Radio Button Methods, Radio Button Events, and Radio Button State Properties, then you may consult the Help documentation provided online and inside the software.
Text Box advanced control
How to conditionally format your results with Text Box advanced controls
About the Text Box
The Text Box enables the users to accept a user input in the form of text and can be used as a string or number data (with the help of the str2num function) for calculations.
The Text Box is located on the Input/Output tab, in the Controls panel, under Advanced Controls.
The user can modify the behavior of the control on input and the resulting output through a Script in the Exec event using the Text Box Class. The appearance of a Text Box can be changed by right clicking on it and choosing “Edit” > “Properties”, and additional customization can be added from the Math Formatting tab.
There are 3 events in the default script for Text Box: Start, Exec and Stop. All actions associated with processing user entries should be written in the Exec event.
The Mathcad Prime Help Center offers information for creating Text Boxes, and provides an Example to be inspected, copied, and modified in addition to the worksheet made available in this article that we will talk about for the rest of this section. Feel free to also follow along with the video:
Text Box use case & code example
Download the accompanying Text Box worksheet here.
Download the worksheet to follow along on your own and explore the Text Box capabilities.
Download HereIn this example, we'll use a scripted Text Box to check a numeric value and display a "Pass" or "Fail" result in the Text Box depending on whether the value exceeds a certain threshold or not. The Text Box will also be formatted differently depending on whether the result is "Pass" or "Fail".
Starting with a set of data, we'll use a List Box to enumerate the values in the data set. Once a value is selected from the list, we'll use the selected value in a scripted Text Box where JScript code will set the Pass/Fail result and format the Text Box appearance.
Step 1
Create a List Box to enumerate the matrix values.
Step 2
Insert a Text Box.
Step 3
Use the Right Mouse Button to click and select "Edit." In the "Exec" event, write code to set the display text within the Text Box and set the appearance of the Text Box. In this example, we'll compare the selected value from the List Box above to the value of variable R, then set the text within the Text Box to Pass/Fail depending on the comparison.
We'll also format the appearance of the Text Box based on whether the result is Pass/Fail.
Scripted Text Boxes can be used in many different scenarios involving calculations. In this example, we checked a selected value in a list against a threshold value and set a Pass/Fail display message accordingly. This can be customized to suit your own purposes.
Text Box usage notes
By leveraging configuration options, integrating with other controls, and handling selections conditionally, you can create dynamic, user-friendly, and robust worksheets. By adhering to these usage notes, you can create Text Boxes that enhance user experience and add flexibility to your worksheets. For more details refer to Advanced Control Text Box Class.
Advanced Control: Slider – COMING SOON!
While we develop a section for the Slider Advanced Control, you can download the worksheets folder here to explore a Slider example in a Mathcad Prime worksheet.
How to convert your Advanced Controls scripts to Mathcad Prime
With the introduction of advanced controls functionality in PTC Mathcad Prime, you may want to convert the scripts from your legacy Mathcad worksheets (such as from PTC Mathcad 15) to Mathcad Prime. In this blog post, read about how to do it, with some useful tips on the process.
Step 1: Use the Mathcad converter
The Mathcad converter can convert advanced controls from legacy Mathcad to Mathcad Prime. Start by opening Mathcad Prime and using the converter.
How to Convert Mathcad 15 Worksheets Into Mathcad Prime
Make sure you move over to Mathcad Prime! In the Input/Output tab, under the PTC Mathcad Worksheets group, select XMCD, MCD Converter. Add your worksheet and click Convert
Visit the Migration PageStep 2: Check the conversion log
Before proceeding, check the conversion log for any issues. Most conversion issues will also be listed as errors in the worksheet itself.
Step 3: Open the converted worksheet
After conversion, you'll receive a Mathcad Prime worksheet with converted controls. Sometimes, you may need to update the script to accommodate your specific workflows.
We recommend recalculating or interacting with each converted control after the conversion. To do this, make sure your Mathcad settings allow the recalculation of advanced controls and that the control is enabled.
Common conversion issues you may encounter
Changes in Radio Button design
In Mathcad 15, radio buttons appeared as multiple buttons with a single selection.
In Mathcad Prime, they appear as a single control with multiple selections. An image is created in the Mathcad Prime worksheet to indicate the position of the radio buttons in the legacy worksheet. You can delete this image if you prefer. I find it useful to delete it and adjust the appearance to the way the new functionality works.
Here is how this radio button control looks before and after conversion. After deleting the extra radio button images, and resizing the control, it looks just like any other radio button:
Inactive methods and properties
Some methods and properties used in legacy Mathcad versions are inactive in Mathcad Prime. You can find a full list of inactive methods and properties in the PTC Mathcad Prime Migration Guide. All currently active properties and methods are listed in the Mathcad Prime Help Center.
When your legacy Mathcad scripts contain inactive properties or methods, they will appear as lines in the script after conversion. These lines do not work, but they also do not cause errors to the script. Essentially, they have no effect on the script.
In the above screenshot, you can see the Recalculate method that was part of the original script in legacy Mathcad. It does not work, but it also does not cause errors. Although not mandatory, it is a good idea to delete this part, to keep the code clean and to avoid confusion. In some cases, you may need to modify your script further, to fit your specific workflow.
Syntax changes
In legacy versions of Mathcad, JScript events used the following syntax:
function MyEventSrc::Event1()
In PTC Mathcad Prime, the double colon (::) is replaced with an underscore (_). Here is the updated syntax:
function MyEventSrc_Event1()
When converting advanced controls from legacy Mathcad to Mathcad Prime, the double colon (::) is not converted to underscore (_), but the script reads it as underscore and works as expected. In this case as well, consider manually changing to the contemporary syntax to avoid confusion and keep consistency.
Converting VBScript to JScript or Python
Another important note is that when converting scripts written in VBScript, it might be a good idea to go one extra step forward and convert them to JScript.
In Mathcad Prime 11, Python was introduced as a scripting environment for advanced controls. You might consider converting to Python as another alternative.
Converting VBScript to JScript or Python can be challenging due to differences in syntax, data types, built-in functions, and more. You will typically need to manually rewrite the script, taking these differences into account. The simplest and most efficient way is to recreate the VBScript logic and then implement it using JScript or Python syntax. You can use online conversion tools or generative AI, but always check the script to ensure it works as expected.
Using Advanced Controls with the Mathcad Prime API
The Mathcad Prime API is different than the legacy Mathcad API. Consequently, when you convert advanced controls that used the legacy Mathcad API, you must rewrite them so they will work with the current Mathcad Prime API.
Read the help chapter on Automation in Scriptable Controls and review the examples provided there to gain better understanding.
Summary & conclusion
To convert your legacy advanced scriptable controls, start by using the Mathcad converter. After conversion, check the conversion log for any necessary adjustments. Use the Mathcad Prime Help Center and the Migration Guide to learn about active, modified, and inactive properties and methods. Some workflows will need no change, others will require syntax modifications, and there will be some workflows that would require more adjustments. If you have controls programmed with VBScript, consider converting them to JScript (or Python, starting with Mathcad Prime 11) to ensure future compatibility.
Concluding thoughts
Advanced controls in Mathcad Prime bring a lot of possibilities for users to customize worksheets to display exactly what they need. By streamlining inputs and automating logic, they help teams work faster and communicate more effectively. Take the time to learn the basics and advanced functions of Mathcad Prime.