MessageBox on a Dropdown List component

Hi everyone,

I have a dropdown list component with two possible choices. When the selection in the dropdown is changed, I have a script running on the propertyChange event that writes a value to a tag.

Immediately after this tag write occurs, I would like to display a message box to confirm that the value has been successfully written.

My current script for the propertyChange event is simple. Could someone please guide me on how to display a message box using system.gui.messageBox?

if event.source.selectedValue == 1:
	system.tag.writeBlocking("MyTagPath", 100)
		
elif event.source.selectedValue == 2:
	system.tag.writeBlocking("MyTagPath", 200)
	

If I insert system.gui.message Box immediately after the 'IF', it's being fired by the proprerty change and so the confirmation message continues to be displayed. And not only once the choice has been changed.

Thanks everyone.

You need to add a filter to the propertyChange script. The dropdown has many properties that can change, and any of them can fire the event.

if event.propertyName == 'selectedValue':
    # do something

Secondly, why don't you bind the tag value to the selectedValue of the dropdown? With bi-direction selected, the tag writes are automatic, no scripting needed.

3 Likes

it works! thanks a lot! :folded_hands:

I don't bind the tag value to the selectedValue of the dropdown because I need to write a float value and the selected value of the component is integer

If it's always the same tag, i'd create a custom property and bi-directionally bind it to the tag.
Then write to that property when the dropdown selection change,
and add another change script to open your message box when the custom prop changes.

edit:
Actually... I missed the part in @dkhayes117 's answer that said to bind the tag to the dropdown's value.
That's probably a better approach.

bind a derived tag with a float/int conversion for writeexpression and readexpression?

Make the value a float then.

If you're pulling it from a database, cast the value to float in the query.
If you're building it with a script, cast it there.

Vision's combobox only supports integer for the actual selected value property.

In this case, it doesn't matter though (since OP's example script was using 100 and 200) - you could just send those as integers and they'll be coerced in the binding/tag system to the closest float value anyways.

Really ? It's been so long since I've used vision...
But why, though ?

At this point, the answer is lost to time. It probably made sense at one point as an easy default, and it's never been worth the risk/complexity to make it smarter. Vision's core components are, for better or worse, pretty consistent about sticking to a single core numeric Java type for properties - that's why the spinner has separate double and integer values: Vision - Spinner | Ignition User Manual

1 Like

There's no common supertype that would cover all of the data type possibilities, so a chameleon property would have to take java.lang.Object. That has negative consequences all over the place. Makes my head hurt.

1 Like