# Referring to label values in code

**URL:** <https://forum.inductiveautomation.com/t/referring-to-label-values-in-code/112>\
**Category:** Archived Topics\
**Created:** [September 26, 2006, 9:01pm UTC](https://forum.inductiveautomation.com/t/referring-to-label-values-in-code/112 "2006-09-26T21:01:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![David](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@David](https://forum.inductiveautomation.com/u/David)\
**Post date:** [September 26, 2006, 9:01pm UTC](https://forum.inductiveautomation.com/t/referring-to-label-values-in-code/112/1 "2006-09-26T21:01:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [September 26, 2006, 9:52pm UTC](https://forum.inductiveautomation.com/t/referring-to-label-values-in-code/112/2 "2006-09-26T21:52:24Z")

</div>

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:

```auto
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,

---

<div class="post-metadata">

**Author:** ![David](https://avatars.discourse-cdn.com/v4/letter/d/aeb1de/32.png) [@David](https://forum.inductiveautomation.com/u/David)\
**Post date:** [September 26, 2006, 10:10pm UTC](https://forum.inductiveautomation.com/t/referring-to-label-values-in-code/112/3 "2006-09-26T22:10:16Z")

</div>

Works like a charm… Thanks.
