Results 1 to 14 of 14

Thread: Difference Between "Me.Close" and "End" for Exit Function

  1. #1

    Thread Starter
    Member Jericho's Avatar
    Join Date
    Mar 2009
    Posts
    36

    Difference Between "Me.Close" and "End" for Exit Function

    Just curious on what the difference is between the "Me.Close" and the "End" code for Visual Basic in terms of writing a Exit Button?

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Difference Between "Me.Close" and "End" for Exit Function

    What are you trying to do?
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Difference Between "Me.Close" and "End" for Exit Function

    Quote Originally Posted by Jericho View Post
    Just curious on what the difference is between the "Me.Close" and the "End" code for Visual Basic in terms of writing a Exit Button?
    "End" and "Application.Exit" do a hard thread terminate. No events are raised and no cleanup code runs it simply terminates the thread (the application) at that point.

    You should just use Me.Close on the main form to exit your app.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Difference Between "Me.Close" and "End" for Exit Function

    Quote Originally Posted by JuggaloBrotha View Post
    "End" and "Application.Exit" do a hard thread terminate. No events are raised and no cleanup code runs it simply terminates the thread (the application) at that point.

    You should just use Me.Close on the main form to exit your app.
    That's not quite true.

    End does indeed terminate the application immediately. That's very bad, so you should NEVER use End.

    Application.Exit exits the app no matter where it's called from, but all appropriate events are raised and all appropriate cleanup is performed. Application.Exit is generally what you should call when you want to exit the application, especially if you are not calling it from the main or last form. Note that calling Application.Exit does bypass the Closing and Closed events of your forms but FormClosing and FormClosed are raised.

    Me.Close simply closes the current form. If the current form is the last or main form then that will also exit the app, depending on your shutdown settings.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Difference Between "Me.Close" and "End" for Exit Function

    Quote Originally Posted by jmcilhinney View Post
    Application.Exit exits the app no matter where it's called from, but all appropriate events are raised and all appropriate cleanup is performed. Application.Exit is generally what you should call when you want to exit the application, especially if you are not calling it from the main or last form. Note that calling Application.Exit does bypass the Closing and Closed events of your forms but FormClosing and FormClosed are raised.
    Really? Unless MSDN is wrong...
    CAUTION The Form.Closed and Form.Closing events are not raised when the Application.Exit method is called to exit your application. If you have validation code in either of these events that must be executed, you should call the Form.Close method for each open form individually before calling the Exit method.
    Application.Exit Method, first MSDN link on a google search.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Difference Between "Me.Close" and "End" for Exit Function

    Quote Originally Posted by JuggaloBrotha View Post
    Really? Unless MSDN is wrong...Application.Exit Method, first MSDN link on a google search.
    That's the documentation for .NET 1.1. It was an issue that Closing and Closed events were not raised when Application.Exit was called, which was the reason that they added the FormClosing and FormClosed events in .NET 2.0.

    http://msdn.microsoft.com/en-us/library/ms157894.aspx
    The Exit method does not raise the Closed and Closing events, which are obsolete as of .NET Framework 2.0.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Difference Between "Me.Close" and "End" for Exit Function

    I guess I hadn't seen that .Net 1.1 doc came up first in the google search (why doesn't MSDN show which FW doc you're looking at on the pages anymore?)

    In either case, I've never seen a need to do a hard exit ("End" or "Application.Exit") anyways.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Difference Between "Me.Close" and "End" for Exit Function

    Oh but it does... it's in the TOC...

    -tg
    Attached Images Attached Images  
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Difference Between "Me.Close" and "End" for Exit Function

    Quote Originally Posted by techgnome View Post
    Oh but it does... it's in the TOC...

    -tg
    Right, but I was referring to the dropdown or whatever that was on the page, so you could change the FW doc version of the current page you're on. It used to sit conveniently in the top right and they took it out.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Difference Between "Me.Close" and "End" for Exit Function

    OH... yeah... I know... I'm not sure what the thought was behind that thought process... I think in thier efforts to "simplify" it... they made it more confusing.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Difference Between "Me.Close" and "End" for Exit Function

    Quote Originally Posted by JuggaloBrotha View Post
    Right, but I was referring to the dropdown or whatever that was on the page, so you could change the FW doc version of the current page you're on. It used to sit conveniently in the top right and they took it out.
    They didn't take it out. They just gave you options. Click Preferences and select Classic view.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  12. #12
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Difference Between "Me.Close" and "End" for Exit Function

    Quote Originally Posted by jmcilhinney View Post
    They didn't take it out. They just gave you options. Click Preferences and select Classic view.
    What "Preferences" ? I don't see any such link for Preferences on MSDN.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  13. #13
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: Difference Between "Me.Close" and "End" for Exit Function

    Quote Originally Posted by techgnome View Post
    What "Preferences" ? I don't see any such link for Preferences on MSDN.

    -tg
    It's in the top right corner.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  14. #14
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Difference Between "Me.Close" and "End" for Exit Function

    ahh.... if one is logged in... which most of the time I'm not. Got it.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

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



Click Here to Expand Forum to Full Width