# Scripting Label Values

**URL:** <https://forum.inductiveautomation.com/t/scripting-label-values/4008>\
**Category:** Ignition\
**Created:** [February 15, 2012, 4:50pm UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008 "2012-02-15T16:50:33Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [February 15, 2012, 4:50pm UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008/1 "2012-02-15T16:50:33Z")

</div>

round( (({CO2 Tanks/Tank 2 Level Row}/380)\*100), 0 ) gives me the value I want.  
I see prefix and Suffix fields that I am using. I see Font options, but if I change this it changes all Prefix, Suffix and values to a static setting.

How can I script this to dynamically change font and color based on value?

Tank\_Value = round( (({CO2 Tanks/Tank 2 Level Row}/380)\*100), 0 )  
Tank\_Value\_Color = “red”

If(  
Tank\_Value \> 60,  
Tank\_Value\_Color = “green”,  
if(  
Tank\_Value \> 30 ,  
Tank\_Value\_Color = “black”,  
Tank\_Value\_Color = “red”  
)  
)

How do I return the tank value with the correct formatting?  
I cannot even declare Tank\_Value as a variable equal to round( (({CO2 Tanks/Tank 2 Level Row}/380)\*100), 0 )

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [February 15, 2012, 6:16pm UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008/2 "2012-02-15T18:16:30Z")

</div>

Users browsing this forum: jantonevich, JordanCClark, MSN NewsBlogs and 4 guests

Wow… MSN on the ignition board? Interesting.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 15, 2012, 6:21pm UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008/3 "2012-02-15T18:21:30Z")

</div>

Bots will browse the forums to add/update their search engines.

Right-click on the label. Go to Customizers → Style Customizer. You should then be able to change the style of the label however you wish. 🙂  
 ![](https://us1.discourse-cdn.com/inductiveautomation/original/1X/34db49dcccc279989bba78ec614e20d7695628f8.png)

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 15, 2012, 6:26pm UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008/4 "2012-02-15T18:26:25Z")

</div>

For the tank value try:

toInt(round( (({CO2 Tanks/Tank 2 Level Row}/380)\*100), 0 ))

I think the round function coerces the value to a float, even though it (the value) needs to be an integer…

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [February 15, 2012, 6:37pm UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008/5 "2012-02-15T18:37:39Z")

</div>

I am looking for a way to script so that my labels will dynamically change.

so if my value is 88 my output would look like this:  
My Value is [color=#00FF00] 88[/color]

so if my value is 40 my output would look like this:  
My Value is [color=#FFFF00] 40[/color]

so if my value is 15 my output would look like this:  
My Value is [color=#FF0000]15 [/color]

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 15, 2012, 6:41pm UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008/6 "2012-02-15T18:41:31Z")

</div>

Ah! You should be abel to do it as html. I can’t give an example quite yet 'cause I’m on my way to a meeting.

After it’s over, I’ll post an example window… 🙂

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [February 15, 2012, 6:47pm UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008/7 "2012-02-15T18:47:06Z")

</div>

> [@JordanCClark](#):
>
> After it's over, I'll post an example window... 🙂

I would really appreciate that. I am having a hard time knowing where I can input logic and how and where to return to and from. If only it was as simple as php or .net....

css/html formatting options would be great. I don't know how to make it dynamic. The user manual only gives snip-its.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 15, 2012, 7:41pm UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008/8 "2012-02-15T19:41:49Z")

</div>

Here you go.

I added a dynamic property to the label called StatusColor. It holds the color name according to the setpoint values (I used the cascaded If-Then you posted earlier. 😉 )

The Text property is a concatenated string that puts together all the html code to get the disired output.  
[Tank with html label.vwin](https://us1.discourse-cdn.com/inductiveautomation/original/1X/bcac4d15c50eb6a3eb4c1af345927872a02cfe18.vwin) (6.49 KB)

---

<div class="post-metadata">

**Author:** ![ecujak](https://avatars.discourse-cdn.com/v4/letter/e/839c29/32.png) [@ecujak](https://forum.inductiveautomation.com/u/ecujak)\
**Post date:** [February 15, 2012, 8:38pm UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008/9 "2012-02-15T20:38:32Z")

</div>

Oh this is beautiful.

Do you have anymore examples of how to use scripting. I learned more with your exported window in minutes than I have from reading the user manual for days.

Thank you sir. I wish there are some kind of like or mod points for this. Thumbs up and thank you for your time.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 15, 2012, 9:22pm UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008/10 "2012-02-15T21:22:03Z")

</div>

> [@ecujak](#):
>
> Do you have anymore examples of how to use scripting...

The answer is, of course, "It depends"... 😆

I've got quite a bit of stuff scattered around on the forum, some more stuff here at work. Whether it's actually useful or not is a matter of some conjecture! ![:mrgreen:](https://us1.discourse-cdn.com/inductiveautomation/original/1X/d23659b203d2d24d394be983a52adb2fa6fe23d4.gif "Mr. Green")

Usually, I'll make a window for whatever someone is trying to do, keeping it as self-contained as possible.

---

<div class="post-metadata">

**Author:** ![billymac00](https://avatars.discourse-cdn.com/v4/letter/b/74df32/32.png) [@billymac00](https://forum.inductiveautomation.com/u/billymac00)\
**Post date:** [February 17, 2012, 3:06am UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008/11 "2012-02-17T03:06:25Z")

</div>

go easy,first post, only started messing with this today (in my “spare” time)  
My question is to confirm whether I need scripting to do the value conversions on a window from the PLC counts. I searched for “4095” and found nothing.  
SO, Ignition is such that one embeds a script for such conversion for each indiv value, everytime it is used?  
I’ll continue to mess about, but I read 2 PLC registers and the values did not match the counts I saw in my PLC view. The tags just declared as unsigned 16bit if I recall. It’s probably something basic.  
Also, I presume the \*.vwin scripts I see in posts must be viewed in Ignition?  
Thanks

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 17, 2012, 10:54am UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008/12 "2012-02-17T10:54:01Z")

</div>

[quote="billymac00"]go easy,first post, only started messing with this today (in my "spare" time)  
[/quote]

No worries! Everyone is new at one time! 🙂

> [@billymac00](#):
>
> My question is to confirm whether I need scripting to do the value conversions on a window from the PLC counts.

I get to use my stock answer for such things: "It depends." Seriously, though, an example of what is in the PLC register to what you're seeing in Ignition will go a long way. My gut tells me that that the PLC register is in BCD, but it's something to verify before I go completely off-base.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [February 17, 2012, 12:10pm UTC](https://forum.inductiveautomation.com/t/scripting-label-values/4008/13 "2012-02-17T12:10:11Z")

</div>

Oh! Almost forgot… okay, I did forget. But I remembered, and that’s the important thing! 😆 What PLC are you using? A PLC side solution likely exists as well. That way you have extra options. That whole “multiple ways to skin a cat” thing, which is good… unless you’re a cat… 😒
