Skip to main content
3-Newcomer
August 5, 2025
Question

How to create a conditional text field

  • August 5, 2025
  • 2 replies
  • 1373 views

I am creating a template in Mathcad 15 that automatically pulls data from an excel workbook and populates various variables with that data. I want to setup a conditional textbox that displays a warning if a particular variable is 0 but is not visible otherwise. Is there a way to do this? 

2 replies

25-Diamond I
August 6, 2025

Not sure what exactly you mean by "textbox".

If you are talking about the region called "Text Box" by PTC Prime, the answer is "no". These Text Boxes can only be created manually by pressing Ctrl-T and typing the text.

Of course you could use a small program sequence using the if-statement to return a text string. But the program would be visible in any case and the the string at best could be an empty string.

Werner_E_0-1754464258623.png

You could hide the creation of the text in collapsed region, but in case that no warning is to be issued, you would still see

Werner_E_1-1754464325716.png

or any text indicating that all is OK.

 

You can also use a scripted "Text Box" (-> Advanced Controls) and its not really clever that PTC had chosen the same name for them as for the text region.

Here you have more control concerning font, font size, font color or background color. Examples for this were posted here in the forum a couple of times. But it still applies that in case no warning is necessary, that Text Box won't vanish. It could display a different text or no text at all but it still would be here.

 

 

 

23-Emerald IV
August 6, 2025

The OP uses (real) Mathcad 15...

 

Luc

25-Diamond I
August 6, 2025

@LucMeekes wrote:

The OP uses (real) Mathcad 15...

 

Luc


Oops, I obviously overlooked that.

23-Emerald IV
August 6, 2025

You could use an expression like:

LucMeekes_0-1754471089945.png

The variable will have the value of Excelvalue if that is not zero, otherwise its value is a string "Warning!" and any numerical calculations your sheet may try to do with Variable will throw an error, unless you check for a variable being a string. Some example:

LucMeekes_2-1754471428272.png

But if you go this far, then it's just as easy (or even easier) to check for a zero value of Variable before attempting calculation.

Your choice.

 

Success!
Luc

3-Newcomer
August 6, 2025

This is the way I currently have it but I was hoping for a slightly more elegant solution. The ideal solution is to have a field that is highlighted red but only appears if the value is 0 and is not visible otherwise. 

16-Pearl
August 6, 2025

In both Legacy Mathcad and Prime, you can set up a TextBox Scripted Control.  I think in your version of Mathcad it required a VB script to control the behavior of the TextBox.   Pass the TextBox the input variables that you want it to be conditioned on and set the message, text color, and text background conditionally, based on the input variables.   You can hide the inputs (only showing the TextBox) for a clean look.  This is a pretty standard use for Advanced Controls and the help should give you some examples.  The VB Script is pretty simple.  I'd post an example, but I haven't used Legacy Mathcad in a decade.