# Scripting for text box's

**URL:** <https://forum.inductiveautomation.com/t/scripting-for-text-boxs/18672>\
**Category:** General Discussion\
**Tags:** scripting\
**Created:** [June 29, 2018, 6:20pm UTC](https://forum.inductiveautomation.com/t/scripting-for-text-boxs/18672 "2018-06-29T18:20:19Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [June 29, 2018, 6:20pm UTC](https://forum.inductiveautomation.com/t/scripting-for-text-boxs/18672/1 "2018-06-29T18:20:19Z")

</div>

So I’m relative new to Python and Ignition to say the least. I have a dropdown menu that has two column and several rows of data manually entered into it. I’m having difficulty with some of the callouts in the code. What I would like to do is take data from the table of the dropdown menu and post it into another TextFeild box. I have accomplished this just by using binding but I would like to know how to do it with code. Here is a picture of what I’m trying to do. When I select data something in the blue I would like the correspond number to appearing in the empty red text box.

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/8/8076ecab65e048fa06b2728ee81f7b8a274e5670.PNG)

Here is a rough outline of my terrible code. As a side note I don’t know why there is a error in my “if” statement.  
def fillwell1x():  
data = event.source.getComponent(“Table”).data  
for row in range (data.rowCount):  
for col in range (data.rowCount):  
value = data.getValueAt(row,col)  
#Error in if/else statment  
if value = ‘’’\<1 cfu/ 100ml (ECC)’’’:  
print “Negative Test Results”  
else:  
print “Positive Test Results”

Like I said I’m a big rookie at this so I’m excited to learn.

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [June 29, 2018, 6:25pm UTC](https://forum.inductiveautomation.com/t/scripting-for-text-boxs/18672/2 "2018-06-29T18:25:10Z")

</div>

Regarding the if statement: in Python, “=” assigns a value while “==” checks for equality. I believe you want:

```auto
if value == '''<1 cfu/ 100ml (ECC)''':
   print "Negative Test Results"
else:
   print "Positive Test Results"

```

_Tip: to make code easy to read on forum as above, place three grave/reverse quote marks (usually to left of “1” on keyboard) before and after code._

---

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [June 29, 2018, 6:29pm UTC](https://forum.inductiveautomation.com/t/scripting-for-text-boxs/18672/3 "2018-06-29T18:29:44Z")

</div>

Ah I see. Thank you!

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [June 29, 2018, 6:36pm UTC](https://forum.inductiveautomation.com/t/scripting-for-text-boxs/18672/4 "2018-06-29T18:36:00Z")

</div>

> [@agweb.salinas](#):
>
> When I select data something in the blue I would like the correspond number to appearing in the empty red text box.

To do this in a script, you'll need your script to:

1. Get table data (yours already does)
2. Get value from dropdown
3. Find row containing value from #2 in Label column of table data
4. Write value from Value column of table data in row found in #3 to the text box value

---

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [June 29, 2018, 7:24pm UTC](https://forum.inductiveautomation.com/t/scripting-for-text-boxs/18672/5 "2018-06-29T19:24:22Z")

</div>

Yeah my main problem is I’m unfamiliar with the callout in ignition.

if I just had a variable:

Value = “Hello World”  
What would be the the line of code or call out to print that code into a new text box since just stating “print” wont define a location in ignition for it to print to?

---

<div class="post-metadata">

**Author:** ![Brian](https://avatars.discourse-cdn.com/v4/letter/b/97f17d/32.png) [@Brian](https://forum.inductiveautomation.com/u/Brian)\
**Post date:** [June 29, 2018, 7:57pm UTC](https://forum.inductiveautomation.com/t/scripting-for-text-boxs/18672/6 "2018-06-29T19:57:05Z")

</div>

You will need to get a reference to the text box you want to change, and set the .text property. See this page for an overview of the process:  
[https://docs.inductiveautomation.com/display/DOC79/Component+and+Window+Scripting](https://docs.inductiveautomation.com/display/DOC79/Component+and+Window+Scripting)

Depending on where you are putting the scripting, you will probably end up with something like:

```auto
event.source.parent.getComponent('Text Field').text = "Hello World"

```

or

```auto
event.source.parent.getComponent('Text Field').text = Value

```

---

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [June 29, 2018, 8:47pm UTC](https://forum.inductiveautomation.com/t/scripting-for-text-boxs/18672/7 "2018-06-29T20:47:45Z")

</div>

Alright I feel like I’m definitely getting closer on getting the solution on this code. Here is what I have. I read that it is easier to deal with as a python data set so I converted it over.

 ![](https://us1.discourse-cdn.com/inductiveautomation/original/2X/e/e7b9e2bccd8cce6a3333b6c90767a1fa140074be.PNG)

When I run it in the designer it tells me there is an error on line 3. Message says “Row sequence subscript must be an integer”. I’m confused because from what I read a .selectedStringValue can be an alpha numeric value. Additionally I know this code is not grabbing the corresponding dropdown. I’m just try to grab the first data point before I go onto bigger things.

---

<div class="post-metadata">

**Author:** ![Paul.Scott](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul.scott/32/4578_2.png) [@Paul.Scott](https://forum.inductiveautomation.com/u/Paul.Scott)\
**Post date:** [June 29, 2018, 9:25pm UTC](https://forum.inductiveautomation.com/t/scripting-for-text-boxs/18672/8 "2018-06-29T21:25:35Z")

</div>

```auto
code = pyData[selRow][0]

```

selectedStringValue can potentially contain numeric values, but the property itself is a string, thus that property will always return a string.

Not certain what the dataset on your dropdown looks like right now, but if it contains values that are easily converted to numerical, you can use Python’s int() function to cast the value as an integer (alternatively, you could use the Selected Value property on the dropdown instead of the Selected String Value)

```auto
code = pyData[int(selRow)][0]

```

However, if you’re trying to check the string value the user selected in the dropdown, then you already have that in `selRow`, so…

```auto
if selRow == "<1 cfu/ 100ml (ECC)":
 code = "Negative Test Result"

```

---

<div class="post-metadata">

**Author:** ![witman](https://avatars.discourse-cdn.com/v4/letter/w/d2c977/32.png) [@witman](https://forum.inductiveautomation.com/u/witman)\
**Post date:** [June 29, 2018, 9:29pm UTC](https://forum.inductiveautomation.com/t/scripting-for-text-boxs/18672/9 "2018-06-29T21:29:28Z")

</div>

> [@agweb.salinas](#):
>
> When I run it in the designer it tells me there is an error on line 3. Message says "Row sequence subscript must be an integer".

This is because `selRow` must be a number (not string) to designate row number in pyData. You are assigning the string in Label column to it by using `selectedStringValue`. Use `selectedValue` instead. With the values shown at the top, you'll need to subtract 1 from `selectedValue` to get the row number (row numbering starts at zero, not 1).

---

<div class="post-metadata">

**Author:** ![agweb.salinas](https://avatars.discourse-cdn.com/v4/letter/a/3ec8ea/32.png) [@agweb.salinas](https://forum.inductiveautomation.com/u/agweb.salinas)\
**Post date:** [June 29, 2018, 10:33pm UTC](https://forum.inductiveautomation.com/t/scripting-for-text-boxs/18672/10 "2018-06-29T22:33:58Z")

</div>

That worked yay!!!  
Thanks for the help guys I’m kinda throwing myself into the middle of all this so I appreciate the helpful replies.
