Community Tip - Stay updated on what is happening on the PTC Community by subscribing to PTC Community Announcements. X
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?
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.
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
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.
The OP uses (real) Mathcad 15...
Luc
@LucMeekes wrote:
The OP uses (real) Mathcad 15...
Luc
Oops, I obviously overlooked that.
You could use an expression like:
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:
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
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.
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.
@JY_13955996 wrote:
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.
The problem is the "is not visible otherwise". You cannot make the TextBox make disappear. It will always be there. But you can change foreground and background color (maybe set both to white to make the box "disappear") and of course font, font size and text displayed.
Its also possible to let a Warning window pop up in case of a result is zero which then has to be clicked away.
See the attached MC15 sheet for a suggestion.
Because the sheet contains a scripted control you will be asked if you want to disable scripts. Your answer should be "no".
... or just change the TextBox text to an empty string, "".
@JeffH1 wrote:
... or just change the TextBox text to an empty string, "".
Yes, this would spare changing the text color to white (or paper color). Background color would still have to be set to something 'invisible' and the whole TextBox still would be there, even though less obvious.
I tried to change width and height of the box to make is smaller when no message should be shown, but the component used seems (amongst others) not to support those hidden properties.
If you're using (Mathsoft) Mathcad 15, one option might (and I say might) be to create a TextBox and then populate it using automation. Possibly by having a control that takes the desired value as an input and then searching for and updating the TextBox accordingly. ISTR that you could tag a region in M15, thus making it easy to select any given region.
I said might because I don't recall whether M15 could update TextBoxes via automation programmes, but there might be other ways around that problem.