PDA

View Full Version : [SOLVED] When does Exit Sub not Exit Sub?



mdmackillop
03-21-2005, 05:23 PM
Inspiration sought for peculiar behavior in this question.
http://www.vbaexpress.com/forum/showthread.php?goto=newpost&t=2412
Test file attached.

sandam
03-21-2005, 06:08 PM
Probably stack related. it may be that the commands are improperly pulled off the stack after the exit sub call is made and that's why it continues to run the piece of code afterwards. It "misses" the finish sub call... Then again I could be horribly mistaken :).

Steiner
03-22-2005, 01:53 AM
That should be because of the recursive call. Try to place the breakpoint right inside DoSearch and go through the whole program step by step.
After the messagebox pops up and asks you for another search, you call LineSearchTest01 again, so that method is running twice now! (The first run did not finish yet, it just calls another instance)

Exit sub now exits the 2nd instance and you are left in the first one right after the recursive call at the endif.

Cyberdude
03-22-2005, 10:05 AM
Sandam made a comment about the "stack" which piqued my interest. Way back in the days of the old IBM PL1 compiler, it had a way to place commands in the stack so that they would execute after the program terminated. Does VBA have such a facility? For example, could I stack the commands to open another workbook just before closing the current one? That would allow the current workbook to close BEFORE opening the next one in a daisy chain fashion.