Type Into: Index and length must refer to a location within the string. Parameter name: length

Hello all,

I am getting errors as Type Into: Index and length must refer to a location within the string.
Parameter name: length

image

Can u pls tell me where I did the mistake

image

Thank you,

@tkiran

Please check if row(1) is returning any values by debugging. This usually happens if the string that you’re trying to substring is empty.

Also, are you reading the Excel file from column A or column B?

row isn’t an array. Row.Item is an array containing the columns. I assume you’re trying to get the value of the second column (index 1) so change it to…

row.Item(1).ToString.Trim.Substring(0,12)

Hello rahul,
It enters correctly but i am getting error
when i am de-bugging returning " ",
reading Column B

Preparation_File_Reading.xaml (19.0 KB)
pls find my xaml…

pls correct me where i am wrong

@tkiran

If you are reading from column B, row(1) must refer to items in column C and I also notice in the logs that the first row item that ends with 30000 is printed correctly.

The second row in column C is empty and the bot is unable to substring the empty value, thus the error.

You could add an empty check to identify this or maybe enter any default value, as per your requirement.

Thank you for reply,

How to avoid in empty cells … while doing substring.

If I fill something in empty cells it works fine… No error …

How to avoid this error when empty cells …

@tkiran

You could use an if condition with the below condition:

String.IsNullOrEmpty(row(1).ToString.Trim.Substring(0,12))

Inside the then part, have a log message and in the else part, have your Type Into activity.

Hi Rahul,

I have done changes as u mentioned i am confused what to fill in type into activity…
can u pls help me…

hi @tkiran - Please check the locals tab for the value where the error occurs.

Also, if possible please share the sample excel sheet after masking/removing sensitive info.

Hi guru,

ABC.xlsx (16.8 KB)
Preparation_File_Reading.xaml (19.0 KB)

@tkiran

Don’t use substring inside the if condition.

Put the below condition inside if:
String.IsNullOrEmpty(row(1).ToString)

Your Type Into can remain the same.

Hi rahul ,
Thank you so much… it is working fine :grinning:

1 Like

Hi Rahul,

One small doubt if I want to type into other columns like C, D, E then what will be the condition can u pls help me…

@tkiran

For null check the condition would be the same except you need to change the column index value like row(2), row(3) etc.

Also, please check the values returned for merged cells, like the second row in columns B and C.

Hi rahul,

Thank you for your great support … it is done as you mentioned it works

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.