Question Unwanted Sub Routine Recursion

mpiontek

New member
Joined
Feb 13, 2009
Messages
4
Programming Experience
10+
I have a rather strange problem that I haven't a clue as to the cause. I have a user control that fires off a single event. The event has a parameter used to determine the action to be taken by the main form. The event handler in the main form contains a single Select construct that takes some action determined by the parameter. The problem is that the routine continues to call itself up to 11 times after the initial call is processed. I've stepped through the code and it simply goes from the End Sub right back to the beginning. The Call Stack only shows the calling routine and the handler. I've gotten around the problem by sending the parameter ByRef and setting it to an empty string after the initial call. This limits the repeated processing but doesn't really fix the problem. Any ideas?
 
A method doesn't get called multiple times unless you have code that does this. An event handler is called multiple times if either (a) the class raises the event multiple times, or (b) you have added the event handler multiple times for same object.
 
Thanks, John. It was, indeed, being added multiple times. There is another user control that is instantiated as needed from an array. I added the single event handler to the same routine that added the events for the control array. Sometimes my brain just needs a push before the first few cups of coffee kick in. Or maybe I just shouldn't code until after lunch.
 
Back
Top