Extracting ImageRectangle Coordinates from Excel to get Click Position Gives Error

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.

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,

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]’

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:
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

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