Referring to label values in code

Hi all: I have a screen that has 14 tanks. Depending on the contents of a dropdown list, the screen shows the contents of one of several cellars; the different cellars have differing numbers of tanks, and the visible property of the tank containers is turned on or off appropriately. Each of the 14 tank containers has the same controls for temps, pressures, etc. So far so good.

Some cellars are hooked up to factorysql and we have lots of data. Others have less data. The two sets are kept on different servers, different dbs, etc.

When the user mouse clicks on a tank container, I would like to direct him to the appropriate History_Graph screen. For the factory sql tanks I am using your pre-build tank history graph. It requires one parameter, the tank number. I can capture that from the tank cellar screen. The non-Factorysql tanks have a different history graph screen, which requires a different parameter (let’s call it BATCHID – that is also in each tank container in a hidden field).

My mouseclicked event for the first tank container cntTank1 is as follows:

Tank = event.source.parent.getComponent(“cntTank1.lblTank.text”)
FERMID = event.source.parent.getComponent(“cntTank1.lblFermid.value”)
print ("The Tank and Fermid are: "), Tank , " ", FERMID
if Tank > 800:
app.nav.swapTo(“Graph_Historical”, {“strTank”: Tank})
else:
app.nav.swapTo(“wnChartSingle”, {“FERMID”: FERMID})

Tanks 800 and up are on factory sql, anything else is not. Some tanks are strings (as in U12, rather than 467 or something). I suspect that will mess up the if statement, but really first things first…
When I print this statement to the debug window, I find that both variables are empty. Any thoughts on what I’ve missed?

Also, is there an elegant way in python to check if a variable is in a list? Ex. in T-SQL

IF tank NOT IN (‘901’,‘902’,‘903’,‘904’) etc.

TIA D. Lewis

Hi David,

The problem with that script is in the call to getComponent()
getComponent() is a function of the Container component. It retrieves a reference to the component named in the function. In your script, you are asking the parent container of the source of the event for the component named “cntTank1.lblTank.text”. This component doesn’t exist.

The first two lines of your script should look more like this:

Tank = event.source.parent.getComponent("cntTank1").getComponent("lblTank").text FERMID = event.source.parent.getComponent("cntTank1").getComponent("lblFermid").value

Now, since you said that this code was on the mouse clicked event of the container “cntTank1”, it is redundant to do this:
event.source.parent.getComponent(“cntTank1”)
because “event.source” points to the same object.

So, I think the first two lines of your script should actually look like this:

Tank = event.source.getComponent("lblTank").text FERMID = event.source.getComponent("lblFermid").value

Ok, next up is your comparison in the if. To make that work, you wold have to cast the Tank variable (a string) to an int, like so:

if int(Tank) > 800:

But, you said that sometimes Tank won’t be an integer. In this case, the int() function will throw a ValueError, which we can catch using Python exception handling. So, the whole script might end up looking like this:

[code]Tank = event.source.getComponent(“lblTank”).text
FERMID = event.source.getComponent(“lblFermid”).value
print "The Tank and Fermid are: ", Tank , " ", FERMID
try:
if int(Tank) > 800:
app.nav.swapTo(“Graph_Historical”, {“strTank”: Tank})
else:
app.nav.swapTo(“wnChartSingle”, {“FERMID”: FERMID})
except ValueError:

Tank wasn’t a number… don’t know what you want to do here

[/code]

Now, checking if a value is in a list in Python is amazingly similar to T-SQL:

[code]if myValue not in (‘val1’, ‘val2’, ‘val3’):

do something[/code]

Hope this helps,

Works like a charm… Thanks.