Error at the second pass of the cycle

Hello! Help me please. I have 2 Word documents containing unstructured information on organizations. In both files, the organizations are the same, the numerical indicators are different. For each of these Word documents, I perform a sequence of actions in a for each loop. First, I use regular expressions to extract the metric information I need for each company using regular expressions and store it in a separate array for each metric. This way I have 4 arrays (Array1, Array2, Array3, Array4). Next, I add values ​​from all these 4 arrays to the DataTable (dt). At the first pass of the cycle, everything is successful and there are no errors. And during the second pass for the second file, the Add Data Row error appears: The index was outside the array boundaries. Why it happens? I will be grateful for any help.

Could you test to print the length of all four arrays to the system console? I suspect that the arrays are not of the same length.

Thank you for your answer. It seems to me that if the arrays were of different lengths, then the error would appear on the first pass through the for each loop. but my error occurs on the second pass. What do you think?

Let’s say that Array1 has the length 4 but Array2 has the length 1.

First iteration works fine:

Second iteration:
Array1(1) ← OK
Array2(1) ← Index out of bound since Array2 only has one item

Thanks! I understand what you were talking about! I printed the length of the arrays. On the first iteration of the for each loop, Array1 = 10, Array2 = 10, Array3 = 10, Array4 = 10. And on the second pass through the loop Array1 = 20, Array2 = 20, Array3 = 20, Array4 = 20. That is, the values ​​of the arrays did not seem to be zeroed out before the second circle. Why could this happen?

Ok, that’s strange. Could you test to print the icount too?

On a different note, you can use Snipping Tool to take screen shots and paste it here in the forum. You can find it under the Windows Accessories folder in the start menu.

Hello! Displayed icount. It also does not reset to zero after the first pass through the loop, although the default is 0. What is the best way to do this? Add action assign icount = 0 at the end of the algorithm?

I write messages from my phone, not from the computer I work on. Therefore, it is more convenient to take a photo. :hugs:

Yes, use an Assign activity and set iCount = 0 before the For Each loop.

I tried using Assign Icount = 0 before and after the loop, but it still doesn’t work. Now this is the result:

On the first pass through the loop, the icount values ​​are from 1 to 10, and on the second from 1 to 20! Maybe I have an error somewhere else in the algorithm? But I can’t even imagine where exactly it might be😔

That’s really strange. It should be working now. If you upload your workflow I can take a look.

Imagine! I was so upset with the icount values ​​that I didn’t notice the main thing! As a result of assign icount = 0 before the loop, the out-of-array index error disappeared! And the program works correctly! Thank you so much for your help !!! I wouldn’t have figured it out without you!:raised_hands:

1 Like

I’m glad to hear that you finally solved it! :smiley:

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