Re: public variable problem
Might help to see some code, there are a few possibilities that may be happening. However, if you put a breakpoint on the end of that first loop (or sub) that assigns a value to input, you can confirm that input.item(a) is not nothing (Shift+F9). Then you can step through to the line with the error. However, I suspect that you will find your problem before you reach that line.
As a guess, I expect that you are in some way expecting input to hold a copy of trainingdata(a,0), when in fact trainingdata(a,0) is holding a pointer to an object, and input is holding a copy of that pointer. Thus if anything deletes whatever trainingdata(a,0) is pointing to, then input remains holding a pointer to nothing. Just a guess, though.