Skip to main content
4-Participant
Oct 30, 2025 11:19 AM UTC
Solved

Advanced Controls: TextBox reset in case of undefined variable

Hello

I am using advanced control text box with python to do conditional formatting. Unfortunately if the variable is undefined I cannot reset the formatting to warn the user something is wrong with the control which results in previous value being displayed. Is there any way to to change the text string/background color  in case any variable is undefined?

MK_14262786_0-1761823027339.png


My code below:

def TextBoxEvent_Start():
# TODO: Add your code here
 
pass
 
def TextBoxEvent_Exec(Inputs, Outputs):
 
Outputs[0]['Value'] = TextBox.Text
S = Inputs[0]['Value']
A = Inputs[1]['Value']
 
stringText = TextBox.Text
TextBox.Text = str(round(A/S,2))
 
if S>A:
BackColor = TextBox.BackColor
TextBox.BackColor = "#FF0000"
else:
BackColor = TextBox.BackColor
TextBox.BackColor = "#92D050"
pass
 
def TextBoxEvent_Stop():
# TODO: Add your code here
pass


Thank you
Best regards 

Michal

Werner_E
Werner_EAnswer
25-Diamond I
Oct 30, 2025 10:08 PM UTC

As far as I am aware there is no way to automatically determine if a variable is defined and act accordingly.

But it sure would be a nice to have.

You may consider to post a feature request at PTC support or an "idea" here -> Mathcad Ideas - PTC Community

3 replies

Werner_E
Werner_E25-Diamond IAnswer
25-Diamond I
Oct 30, 2025 10:08 PM UTC

As far as I am aware there is no way to automatically determine if a variable is defined and act accordingly.

But it sure would be a nice to have.

You may consider to post a feature request at PTC support or an "idea" here -> Mathcad Ideas - PTC Community

Translate
4-Participant
Oct 31, 2025 8:14 AM UTC

Thank you for the reply.

I agree that it is somewhat critical to know if the variable is undefined in the scripts.

Do you know what happens if the variable is undefined? Is the script in the control widget not executing at all? 
Unfortunately it seems like I do not have access MathCad Ideas part of the forum so I cannot post it.

Translate
Werner_E
25-Diamond I
Oct 31, 2025 11:57 AM UTC

Do you know what happens if the variable is undefined? Is the script in the control widget not executing at all? 

I don't know for sure but I guess that a scripted control is seen as a math region and so isn't evaluated at all if an undefined variable is used as input.

Translate