# Using variables to create component names

**URL:** <https://forum.inductiveautomation.com/t/using-variables-to-create-component-names/2357>\
**Category:** Archived Topics\
**Created:** [November 19, 2010, 10:48pm UTC](https://forum.inductiveautomation.com/t/using-variables-to-create-component-names/2357 "2010-11-19T22:48:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![DB2](https://avatars.discourse-cdn.com/v4/letter/d/e0b2c6/32.png) [@DB2](https://forum.inductiveautomation.com/u/DB2)\
**Post date:** [November 19, 2010, 10:48pm UTC](https://forum.inductiveautomation.com/t/using-variables-to-create-component-names/2357/1 "2010-11-19T22:48:52Z")

</div>

I’m trying to use a for loop to change the color state of several label. I’ve tried the following syntax with no success.

`value = fpmi.gui.color(238,238,238,255)
word = 'label a'
for i in range(1, 9):
	event.source.parent.getComponent(word+i).background = value`

any suggestions?

---

<div class="post-metadata">

**Author:** ![Robert.McKenzie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert.mckenzie/32/4134_2.png) [@Robert.McKenzie](https://forum.inductiveautomation.com/u/Robert.McKenzie)\
**Post date:** [November 20, 2010, 12:55am UTC](https://forum.inductiveautomation.com/t/using-variables-to-create-component-names/2357/2 "2010-11-20T00:55:11Z")

</div>

Have you tried something like this?`value = fpmi.gui.color(238,238,238,255)
word = 'label a'
for i in range(1, 9):
    name = "word%s" %(i) #this should produce 'label a1' as the name of the component
    event.source.parent.getComponent(name).background = value`

---

<div class="post-metadata">

**Author:** ![AlThePal](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/althepal/32/3603_2.png) [@AlThePal](https://forum.inductiveautomation.com/u/AlThePal)\
**Post date:** [November 20, 2010, 1:16pm UTC](https://forum.inductiveautomation.com/t/using-variables-to-create-component-names/2357/3 "2010-11-20T13:16:34Z")

</div>

I think Bobby’s code should be:`value = fpmi.gui.color(238,238,238,255)
word = 'label a'
for i in range(1, 9):
    name = "%s%d" %(word, i) #this should produce 'label a1' as the name of the component
    event.source.parent.getComponent(name).background = value`

---

<div class="post-metadata">

**Author:** ![Robert.McKenzie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/robert.mckenzie/32/4134_2.png) [@Robert.McKenzie](https://forum.inductiveautomation.com/u/Robert.McKenzie)\
**Post date:** [November 22, 2010, 4:06pm UTC](https://forum.inductiveautomation.com/t/using-variables-to-create-component-names/2357/4 "2010-11-22T16:06:24Z")

</div>

Haha, so it should Al. Thanks for the typo fix!
