# Extracting ImageRectangle Coordinates from Excel to get Click Position Gives Error

**URL:** <https://forums.eggplantsoftware.com/t/extracting-imagerectangle-coordinates-from-excel-to-get-click-position-gives-error/8799>\
**Category:** Eggplant Functional\
**Tags:** excel, script, sensetalk\
**Created:** [April 9, 2024, 5:05pm UTC](https://forums.eggplantsoftware.com/t/extracting-imagerectangle-coordinates-from-excel-to-get-click-position-gives-error/8799 "2024-04-09T17:05:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![EggplantHS](https://forums.eggplantsoftware.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@EggplantHS](https://forums.eggplantsoftware.com/u/EggplantHS)\
**Post date:** [April 9, 2024, 5:05pm UTC](https://forums.eggplantsoftware.com/t/extracting-imagerectangle-coordinates-from-excel-to-get-click-position-gives-error/8799/1 "2024-04-09T17:05:46Z")

</div>

Hi

I have the below code that first pulls the required data from Excel. Then using ImageRectangle the coordinates where the text Label was found is added together with the coordinates of TextBoxOffset to find the location to click so I can enter the required data.

```auto
to handle TextBox FileName, SheetName, CellValue1, CellValue2, TextBoxOffset:[200,-2,0,7]
	Set myExcelFile to Workbook(ResourcePath(FileName))
	Set SheetName to MyExcelFile.Worksheet(SheetName)
	Put Cell(SheetName, CellValue1) into Label
	Put Cell(SheetName, CellValue2) into Input
	put imageRectangle(text:Label)+ TextBoxOffset into OptionArea
	Click center of OptionArea 
	Wait 0.5
	TypeText Input, escapeKey
	Wait 0.3
end TextBox

```

With the above example TextboxOffset values are hard coded and I’m looking to pull these values from Excel along with all the other data. I’ve amended the code as below,

```auto
to handle TextBox2 FileName, SheetName, CellValue1, CellValue2, CellValue3
	Set myExcelFile to Workbook(ResourcePath(FileName))
	Set SheetName to MyExcelFile.Worksheet(SheetName)
	Put Cell(SheetName, CellValue1) into Label
	Put Cell(SheetName, CellValue2) into Input
	Put Cell(SheetName, CellValue3) into TextBoxOffset
	put imageRectangle(text:Label)+ TextBoxOffset into OptionArea
	Click center of OptionArea 
	Wait 0.5
	TypeText Input, escapeKey
	Wait 0.3
end TextBox2

```

But this is failing with the following error. Any idea why this fails when pulling the TextBoxOffset coordinates from Excel please?

> SenseTalk Runtime Exception:  
> Invalid operands for addition: expected numbers, dates and/or lists; got ‘[200,-2,0,7]’ and ‘[391,889,457,902]’

---

<div class="post-metadata">

**Author:** ![DaveHester](https://forums.eggplantsoftware.com/user_avatar/forums.eggplantsoftware.com/davehester/32/104_2.png) [@DaveHester](https://forums.eggplantsoftware.com/u/DaveHester)\
**Post date:** [April 10, 2024, 12:26pm UTC](https://forums.eggplantsoftware.com/t/extracting-imagerectangle-coordinates-from-excel-to-get-click-position-gives-error/8799/2 "2024-04-10T12:26:41Z")

</div>

> [@EggplantHS](#):
>
> ```auto
> to handle TextBox2 FileName, SheetName, CellValue1, CellValue2, CellValue3
> Set myExcelFile to Workbook(ResourcePath(FileName))
> Set SheetName to MyExcelFile.Worksheet(SheetName)
> Put Cell(SheetName, CellValue1) into Label
> Put Cell(SheetName, CellValue2) into Input
> Put Cell(SheetName, CellValue3) into TextBoxOffset
> put imageRectangle(text:Label)+ TextBoxOffset into OptionArea
> Click center of OptionArea 
> Wait 0.5
> TypeText Input, escapeKey
> Wait 0.3
> end TextBox2
> 
> ```

There are two tricks here that are needed to make this work.

- First, understand that lists are displayed within square brackets, but the square brackets are not part of the lists themselves. For this reason, the value in your TextBoxOffset cell in Excel should be '125,-5,200,5 or some similar value. Note, you will need to type an apostrophe in Excel ahead of your list of numbers to force Excel to treat the value as text.
- Secondly, the `imageRectangle` function returns a list, so you will need to force the value from Excel into a list. This is accomplished by using `split by comma` in your code. Here is what worked for me:

```auto
to handle TextBox2 FileName, SheetName, CellValue1, CellValue2, CellValue3
	Set myExcelFile to Workbook(ResourcePath(FileName))
	Set SheetName to MyExcelFile.Worksheet(SheetName)
	Put Cell(SheetName, CellValue1) into Label
	Put Cell(SheetName, CellValue2) into Input
	Put Cell(SheetName, CellValue3) split by comma into TextBoxOffset
	put imageRectangle(text:Label)+ TextBoxOffset into OptionArea
	Click center of OptionArea 
	Wait 0.5
	TypeText Input, escapeKey
	Wait 0.3
end TextBox2

```

Hope this helps,  
Dave

---

<div class="post-metadata">

**Author:** ![EggplantHS](https://forums.eggplantsoftware.com/letter_avatar_proxy/v4/letter/e/90ced4/32.png) [@EggplantHS](https://forums.eggplantsoftware.com/u/EggplantHS)\
**Post date:** [April 10, 2024, 2:54pm UTC](https://forums.eggplantsoftware.com/t/extracting-imagerectangle-coordinates-from-excel-to-get-click-position-gives-error/8799/3 "2024-04-10T14:54:09Z")

</div>

Hi Dave, thank you, that’s worked a treat. Many thanks for the help
