Assigning a value to a variable in code

I have a graph window that retreives data for a tank based on a parameter that is passed in when the window is opened. I have also placed a combo box on the window so that once it is open, users can switch to another tank to view its data.

On the root container is a variable strTank that holds the tank number. It is used in some labels and is also passed to the stored procedure as a parameter.

I would like to assign a new value to that variable when the users selects a different tank using the drop down box. I tried the following but it did not work:

{Root Container.strTank}=={Root Container.cboTank}.selectedValue

Selected value is an integer, and strTank is a string. If I understand correctly, it should be coerced into a string type without explicit conversion. Likely there is some other problem as well. TIA D. Lewis

David - where did you put the line of code that you posted?

You could do this by simply binding the selected value to the root container variable, and vice versa using property bindings (maybe expression bindings if you need to cast strings to ints) - that should work.

Let me know,

Just for the sake of completeness, I wanted to point out the way to do what David originally intended…

First, you can’t do {Root Container.strTank}=={Root Container.cboTank}.selectedValue because the {} is not a real object reference, it’s just telling the scripting engine to retrieve that value and put it in there before executing. To properly achieve this (in this case, going to a custom property), you have to use the “setPropertyValue” function:

event.source.parent.setPropertyValue("strTank", event.source.selectedValue)

*Note: I’m assuming this is being run in the combo box’s PropertyChange action

Now, the downside is that the combo box will not automatically reflect the value passed in when the window opens… for that you’ll have to do some sort of binding, like Carl suggested. I mostly just wanted to point out syntactically how you would do what you specified.

Hope that helps,