4 Replies - 366 Views - Last Post: 08 November 2012 - 01:44 PM Rate Topic: -----

#1 Lukee9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 15-August 12

IF statement when program self terminates

Posted 07 November 2012 - 01:32 PM

Hey, i was wondering if the was anyway to do an if statement just as the program self terminates, i would like to use this so that if the program crashes and self termibates, just as its doing this it will create a crashlog in a certain location, so an if statement would be like If program crashing = true, save crashlog to path, (thats just psuedo code :P). so i was wondering if its possible, and if it is can you give me some links to the msdn pages on the commands/functions to use, thanks :)

Is This A Good Question/Topic? 0
  • +

Replies To: IF statement when program self terminates

#2 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1533
  • View blog
  • Posts: 4,919
  • Joined: 25-September 09

Re: IF statement when program self terminates

Posted 07 November 2012 - 01:52 PM

Not real sure how you would do it. What would you put in it? I mean, the program crashed so I'm thinking it's not going to care what you want at that point :D

Anyway, you might be able to do something like create a file (doesn't have to be anything special) and when the program shuts down normally, delete the file upon closing. Now you start your program and the file exists, you know there was a crash that occurred stopping a normal shutdown.

Maybe someone else can offer something better but again, a crash is an abrupt stop of the logical operation of your code.
Was This Post Helpful? 0
  • +
  • -

#3 Lukee9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 15-August 12

Re: IF statement when program self terminates

Posted 07 November 2012 - 02:27 PM

View PostCharlieMay, on 07 November 2012 - 01:52 PM, said:

Not real sure how you would do it. What would you put in it? I mean, the program crashed so I'm thinking it's not going to care what you want at that point :D

Anyway, you might be able to do something like create a file (doesn't have to be anything special) and when the program shuts down normally, delete the file upon closing. Now you start your program and the file exists, you know there was a crash that occurred stopping a normal shutdown.

Maybe someone else can offer something better but again, a crash is an abrupt stop of the logical operation of your code.

Thats quite a good method but it would say that it crashed if you used windows 7's right click on the program in the taskbar and use close program. So basically the only way they'd be able to shut it down without a crashlog would be to use a close button on the form, which 90% of people wont do :), thanks for your ideas though :D
Was This Post Helpful? 0
  • +
  • -

#4 lar3ry  Icon User is offline

  • Coding Geezer
  • member icon

Reputation: 310
  • View blog
  • Posts: 1,290
  • Joined: 12-September 12

Re: IF statement when program self terminates

Posted 07 November 2012 - 02:57 PM

No, if a user right-clicks on the taskbar icon and selects Close or Exit, the program will go through the same code as it would if the user clicks a close button or the Close icon in the Titlebar, or even if the program gets to an End statement.

The key to what you want to do is to run some code when the form is closing, and there's an event for that. In the Code editor, select Form Events, and then select FormClosing. You can place code in there to do whatever you want before the form closes, even as much as cencelling the close.


    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        ' Do stuff here
    End Sub


Was This Post Helpful? 1
  • +
  • -

#5 Lukee9  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 37
  • Joined: 15-August 12

Re: IF statement when program self terminates

Posted 08 November 2012 - 01:44 PM

View Postlar3ry, on 07 November 2012 - 02:57 PM, said:

No, if a user right-clicks on the taskbar icon and selects Close or Exit, the program will go through the same code as it would if the user clicks a close button or the Close icon in the Titlebar, or even if the program gets to an End statement.

The key to what you want to do is to run some code when the form is closing, and there's an event for that. In the Code editor, select Form Events, and then select FormClosing. You can place code in there to do whatever you want before the form closes, even as much as cencelling the close.


    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        ' Do stuff here
    End Sub


Thanks, helped a lot, and thanks to charlie as well for the initial idea :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1