The "for each" construction attempts to assign the content of the array to the variable for each element of the array.
That means if your array contains (23, 56, 32, 54)
then the first time through the loop "i" will be 23. Next time it's 56.
You need to use
for i = 0 to (ubound(LengthsArr)-1)
Then i will be 0,1,2, etc.
I'll give that a go