+ Reply to Thread
Results 1 to 3 of 3

Coding Convention Questions #4 (One and only one exit from a procedure)

  1. #1
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Question Coding Convention Questions #4 (One and only one exit from a procedure)

    "There should only be one exit from a procedure. Never have multiple Exit Subs (or Exit Functions) throughout your procedure. If you need to exit early, do a GoTo ExitProcedure label instead."

    The above is a school of thought that I have encountered from time to time (and I have started to blindly adopt) however I can't recall ever seeing any clear reason provided on the benefits of doing so.

    Could anyone please explain what the benefit/s is/are?

    (Optional question: Did this practice arise from another earlier language? If so, I'd be interested in knowing the background).
    *******************************************************

    HELP WANTED! (Links to Forum threads)
    Trying to create reusable code for Custom Events at Workbook (not Application) level

    *******************************************************

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Coding Convention Questions #4 (One and only one exit from a procedure)

    Benefit will be in debugging and clean up operations. If there may only be one exit from a routine there is only one place code must reset variables and settings if required. For VBA you may consider enableevents for example.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  3. #3
    Valued Forum Contributor
    Join Date
    08-29-2012
    Location
    In lockdown
    MS-Off Ver
    Excel 2010 (2003 to 2016 but 2010 for choice)
    Posts
    1,766

    Re: Coding Convention Questions #4 (One and only one exit from a procedure)

    Quote Originally Posted by Izandol View Post
    Benefit will be in debugging and clean up operations. If there may only be one exit from a routine there is only one place code must reset variables and settings if required. For VBA you may consider enableevents for example.
    Of course! I overlooked the obvious! Thanks and +1

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Coding Convention Questions #3 (Procedure Naming Conventions)
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 03-31-2014, 09:39 PM
  2. [SOLVED] Coding Convention Questions #2 (To clean up or not to clean up)
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 24
    Last Post: 03-31-2014, 08:18 PM
  3. [SOLVED] Coding Convention Questions #1 (On Error Goto 0 before End Sub)
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 02-05-2014, 01:37 AM
  4. VBA Coding Style - Exit Points - What are good methods for coding Exit Points?
    By CHatmaker in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-11-2013, 05:30 PM
  5. to exit main procedure from procedure called by yhe main
    By kmlprtsngh in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-27-2010, 02:46 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1