Results 1 to 5 of 5

Thread: End program during input validation

  1. #1

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    End program during input validation

    Gentlemen,

    I have a question that I can't seem to find the answer for through google or me lil VB book here. I am aware that if you want to close a form you have me.close but what if you want a program to terminate? Given situation:

    You have failed to give me "Staring Point".
    If you don't give me "Staring Point" the program will terminate.

    I'd like to terminate the entire program based on dialogresult. Do I just kill my main form or is there a line I can put in there to exit program?

    Thanks again for all your help.
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

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

    Re: End program during input validation

    If the code is part of the main form then Me.Close will close that form and exit the application, assuming your shutdown mode is the default "when main form closes". Anywhere else you would need to call Application.Exit.
    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

  3. #3

    Thread Starter
    Addicted Member Abrium's Avatar
    Join Date
    Feb 2007
    Location
    The Great State of Texas
    Posts
    205

    Re: End program during input validation

    app.exit, thanks JM
    Abrium
    Asking the beginners questions so you don't have to!
    If by chance hell actually froze over and I some how helped you... Please rate.

  4. #4
    Hyperactive Member Philly0494's Avatar
    Join Date
    Apr 2008
    Posts
    485

    Re: End program during input validation

    Quote Originally Posted by jmcilhinney View Post
    If the code is part of the main form then Me.Close will close that form and exit the application, assuming your shutdown mode is the default "when main form closes". Anywhere else you would need to call Application.Exit.
    Why is it that in some situations, "End" doesn't work to close the program while "Application.Exit()" will, and strangle enough I've seen "Application.Exit()" fail but when replaced with "End" the program exits as desired?

    I've even experienced cases where End and Application.Exit() fail.. yet Application.ExitThread() succeeds. (Obviously this would only work on the main thread)

    I've seen this several times and I'm always puzzled..

    Btw, I know Application.Exit() can be overruled by other forms, just look at the documentation of the first overload of Application.Exit(e as System...)

    I've never used Environment.Exit(0).. will this always work?
    Last edited by Philly0494; Nov 12th, 2009 at 01:02 AM.

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

    Re: End program during input validation

    Quote Originally Posted by Philly0494 View Post
    Why is it that in some situations, "End" doesn't work to close the program while "Application.Exit()" will, and strangle enough I've seen "Application.Exit()" fail but when replaced with "End" the program exits as desired?

    I've even experienced cases where End and Application.Exit() fail.. yet Application.ExitThread() succeeds. (Obviously this would only work on the main thread)

    I've seen this several times and I'm always puzzled..

    Btw, I know Application.Exit() can be overruled by other forms, just look at the documentation of the first overload of Application.Exit(e as System...)

    I've never used Environment.Exit(0).. will this always work?
    First up, never, ever use End. End is like terminating your process from the Task Manager. There's never a reason to do that in code.

    As for Application.Exit being cancelled by a form, let's keep in mind that this your code we're talking about here. It's your code that would be calling Application.Exit and it's your code that would be cancelling it. If that's not the behaviour you want then why code it in the first place?

    Environment.Exit is what you'd call in a Console app, given that the Application class is a member of System.Windows.Forms and only exists in WinForms apps.
    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

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