Consulting

Results 1 to 4 of 4

Thread: When does Exit Sub not Exit Sub?

  1. #1
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location

    When does Exit Sub not Exit Sub?

    Inspiration sought for peculiar behavior in this question.
    http://www.vbaexpress.com/forum/show...newpost&t=2412
    Test file attached.

  2. #2
    Knowledge Base Approver
    Space Cadet VBAX Tutor sandam's Avatar
    Joined
    Jan 2005
    Location
    London
    Posts
    292
    Location
    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 .
    Nothing annoys a non-conformist more than other non-conformists who refuse to conform to the rules of non-conformity.


    Confused is my normal state of mind


  3. #3
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    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.

  4. #4
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •