So, I was building a simple for loop that contains a call to a function that I created. The function takes as one of it's parameters, an index. The odd thing is that I ALWAYS use a unique name in the function parameter from the value that is being passed in.
example: x = GetWord(counter, text, delimiter)
formal definition: Function GetWord(idx, sentence, delim)
So, as you can see, idx is a copy of counter.
There 2 ways the process can use idx:
ByVal: If you change idx in the function, it does NOT change the value outside the function
ByRef: If you change idx in the function, it WILL change what was passed in. In this example, counter would be the same value as idx when the function was finished.
After all this time, I just learned the hard way that VBScript defaults to using "ByRef"!!!!! So, when I changed the IDX value it changed my counter of my loop. Since I was subtracting 1 from IDX, I was in an endless loop!
To fix it, I just put "ByVal" in front of IDX like this:
Function GetWord( ByVal idx, ByVal sentence, ByVal delim)
I known for years about using byval and byref, but I never realized that byref was the default. It's important to know the difference....as I found out the hard way.