cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get an answer that solved your problem? Please mark it as an Accepted Solution so others with the same problem can find the answer easily. X

Translate the entire conversation x

Advanced Controls: TextBox reset in case of undefined variable

MK_14262786
4-Participant

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

ACCEPTED SOLUTION

Accepted Solutions
Werner_E
25-Diamond I
(To:MK_14262786)

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

View solution in original post

3 REPLIES 3
Werner_E
25-Diamond I
(To:MK_14262786)

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

MK_14262786
4-Participant
(To:Werner_E)

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.

Werner_E
25-Diamond I
(To:MK_14262786)


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.

Announcements

Top Tags