For the most part, my program is working fine, but this procedure is given me issues when used

http://pastie.org/3950400 .. I've messed around quite a bit with it and I can't seem to get it to work.. it either freezes the program or spits out an error like:

>{"Index was outside the bounds of the array."}

> System.IndexOutOfRangeException

> Index was outside the bounds of the array.


If I change line 38 to something like (40) from (-1) the program will just hang and eventually an error will pop up because it hasn't responded.

Thanks in advance.