Nested IF to write to multiple tags

Hi, I am having difficulty in getting this to work any help would be great. Thank you.

What I am trying to accomplish is to first check to make sure the other bay is not started, write to a tag if either product 1 is selected or write to a different tag if product 2 is selected and then write to the tag to start the cycle.

[code]if fpmi.gui.confirm(‘Are you sure?’, ‘Confirm’):

if event.source.parent.Bay2CycleStart == 0:
elif event.source.parent.ProductSelected == 1:
	fpmi.tag.writeToTag("[DnSMySQL]LoadoutPLC/_42_Selected", 1)
elif event.source.parent.ProductSelected == 2:
	fpmi.tag.writeToTag("[DnSMySQL]LoadoutPLC/_55_Selected", 1)

fpmi.tag.writeToTag("[DnSMySQL]LoadoutPLC/StartCycle", 1)	

Ok, and whats the problem that you’re encountering?

It seems to be skipping over the tags for product selected and only writing the tag for cycle start. No errors are generated… I am fairly new to python so I am not sure if there is a different way that I should be trying this.

Ah, what is the datatype of the “ProductSelected” property? Integer, String, …?

It is set as Integer.

Well it sounds like it isn’t 1 or 2. Try printing it to the console to troubleshoot what the value is when that script executes.

That was my on of my first thoughts, so I seperated almost everything first into seperate dynamic properties to help me understand what was happening or not happening, but everything seems to be what it should it just appears that for whatever reason those 42 selected and 55 selected SQL Tags are not changing values. When I just have the writeToTag without the if statement it does work, so I assume that I have something wrong with the nested if statement…

For my test, I have it at 1.

I have a label that tells me that the property is resolving to 1 and also the button is not enabled unless productselected equals 1 or 2, and I do get the enable on the button.

The property productselected is a dynamic property on the same container as the button. The container is 1 layer down from root.

The property productselected is using an expression to evaluate the results from a select statement on another label on the same container. The statements/expressions that each property have are:


if({Root Container.Container.Label 12.text}='42 High Fructose Corn Syrup',1,if({Root Container.Container.Label 12.text}='55 High Fructose Corn Syrup',2,0))


SELECT [d&sproducts].ProductName AS Product FROM [d&sorders] Inner Join [d&sproducts] ON [d&sorders].ProductID=[d&sProducts].ProductID Where [d&sorders].orderID = {Root Container.Order}

The Root Container.Order is a property that is updated by user selection (DropDown List)

Its very simple to tell if your if blocks are executing:

if something == 2: print 'yep, its two' elif something == 5: print 'nope, its five'

And then open the output console to verify.