I understand the concepts of by reference and by value, but has anyone else encountered a problem with passing a variable by reference and then that variable being reset for apparently no reason?

I called something like this:
Code:
subroutine(ByRef oIndex as integer)
And it would set oIndex to 0 after it completed, but it would always have the proper value all the way through the sub routine. Setting oIndex to ByVal solved the problem no sweat, but I was wondering if anyone knows why this happened. It did it on several subroutines.

The Routines only used oIndex as an index for a class/struct, and were used very rarely throughout the subroutine.