dcsimg
Results 1 to 2 of 2

Thread: Forcing an application to close

  1. #1

    Thread Starter
    Member
    Join Date
    May 2019
    Posts
    36

    Forcing an application to close

    Hi,

    Whats the best methord to force a form not a application to close my plan is the following.

    Code:
    Dim msgresult as dialogresult
        Catch ex As Exception
                msgresult = MessageBox.Show("Error while updating the customers record..." & " " & ex.Message, "Deactivate Customer", MessageBoxButtons.OK, MessageBoxIcon.Warning)
                If msgresult = DialogResult.OK Then
                Exit Sub
                End If
    But the Exit Sub or Me.close doesnt close the form. I need to force close the form if a ex.message is caught.
    Last edited by VBJames; Jun 10th, 2019 at 11:15 AM.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    103,251

    Re: Forcing an application to close

    You should never use Exit Sub. It's not a big deal but, if you want to end a method then you should use Return. Using either, the current method will end and control goes back to the calling method. That has no effect on the form's state specifically.

    If you want to close a form then you do one of two things. Firstly, if the form was displayed by calling ShowDialog, you can simply set the DialogResult property. Whatever value you assign is what ShowDialog returns. You can also call Close, in which case ShowDialog will return Cancel. If the form was dispplayed by calling Show, you just call Close.

    Keep in ind that DialogResult and Close are just a property and a method respectively, just like any other. The form won't magically stop executing at that specific point in code. Any code after that will still execute so, if you don't want any code to execute after that, make sure there is no code after that to execute. If you need to use a Boolean flag and some If statements to do that then so be it.

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width