For each row index +1 error message (no line at the position)

Hey every body,

I fall in a problem ! I’m explaining you :

I do a for each in a data table. Until that, no problem :stuck_out_tongue:

My development :

Assign : Val+1= NewDT.Rows(index +1).Item(“Column3”).ToString

If : Condition : row(“Column3”).Tostring.Contains(“1000”) and Val+1.Contains(NumAL)

Add to collection

My problem ? When the for each reach the last row, i have an error message : No line at the position.

Anyone have a method against this problem ?

Thank you so much :slight_smile:

@BaptisteC,

Since you have used Index+1 it in the last row it will check for the row which is not available in your datatable.

Let me say, you have 10 rows in your datatable. Inside the loop at 10th row you are looking the data in the 11th row which is not exists in the datatabel.

You can avoid this using, IF Activity inside the loop, To check whether it is the last row or now with “yourDataTable.Rows.IndexOf(row) <> yourDataTable.Rows.Count”

But I would like to know what you are trying to do by checking the next row value in the current looping mechanism you have.

1 Like

Hi @sarathi125,

It’s a good idea ! I will try it :slight_smile:

This is my case :

I have several blocs like this :

F0 B7 1000 140819FRT3ORDLIV
M2 B7 41087A2000
M2 B7 41087A4000LM330
M2 B7 41087A4000LM340
M2 B7 41087A4000LM350
M2 B7 41087A4000LM360
M2 B7 41087A4000TA400
M2 B7 41087A4000TM000
M2 B7 41087A3001
M2 B7 5 00010006

It’s a capture of a text file but i treat the data on a data table of course.

That’s a second eg :

U2 E1 1000 270616LXIBORDLIV
U2 E1 V2706A2000
U2 E1 V2706A4000AD010
U2 E1 V2706A4000AD030
U2 E1 V2706A4000DA320
U2 E1 V2706A4000TA400
U2 E1 V2706A3002
U2 E1 5 00010004

So, my job is to check differents samples in each bloc. I have to check the type of the bloc “DLIV” for both. After, the ID “41087” for the the first bloc.

I have an input excel file with two column : Type and ID. For eg : DLIV for the type and 41087 for the ID. I have to remove the bloc which match with the Id and type. Then, here my development :

For each row which contain 41087, add to collection and remove it. For each row(“Colum3”) which contain DLIV and that the next row(“Colum3”) contain 41087, add to collection and remove it and to finish for each row(“Colum3”) which contain "5 " and that the last row(“Colum3”) contain 41087, add to collection and remove it.

I expect that i clear. Don’t hesitate to tell me if you want more.

Thank for your help ! :slight_smile:

Hello again @sarathi125,

I tested your method but i still have the error message and i know why. I have the error on my assign activity :

Val+1 = NewDT.Rows(index +1).Item(“Column3”).ToString

The assign is before the if condition of course.

@BaptisteC,

I am not clear on the matching and deleting part.

I assume that those two blocks are text files, if is matches with “DLIV” and “41087” and where we need to delete it, from the Input excel or from the text file.

Any other things we need to check with this?

1 Like

@sarathi125

My excel input (The ** are others types and others ID) :

image

I receive this input all the days.

I have to do the process that i described above. I have lot of conditions that i can’t put here, so long ! :stuck_out_tongue:

I think there are others methods that i can use and especially optimized.

What do you think about my error message for the assign activity (last reply) ?

In this assign activity which part is the left and which part is in the right.

1 Like

@sarathi125

This assign :

The assign is before the if condition. So, as soon as execute the assign activity, it check the row(index +1) and it doesn’t foun the row.

I have the error :

Any idea ? Thank you

You will get No line at the position error for this, since there is no line from the last row when you are trying to use Index +1.

Can you put the assign activity screenshot here for better understanding

@sarathi125

Assign : out_NewDT.Rows(index +1).Item(“Column3”).ToString

If condition : row(“Column3”).Tostring.Contains(“1000”) and NumValCourant.Contains(in_NumAL)

The error come in the assign activity.

Sorry, I am not understanding this point, why we need to check the next row inside the current row in the loop.

When you are at the last row this will throw error only.

1 Like

@sarathi125

I need to check the next row because i have to remove the row before the bloc (bloc = the several row which have 41087) then i try to remove the line which contain “1000” and where the next row contain 41087.

Do you understand ?

Add another if before the if you have showed in your screenshot here, so the add collection will not be executed for the last row

1 Like

Yes, but the robot will have an error when it execute the assign activity. That’s my problem

index%201%20solution

Ok it’s good like this ! Thank you @sarathi125

I need to put the assign between the first and the second If condition :slight_smile:

I think you need to put NumRowDt-1 in that if activity.