Save changes on Exit - Yes, No, Cancel

The construct seemed straightforward to begin with, but . . .

So when the user exits the application, then that is the time to write to a preferences file or do some cleanups etc. Pretty basic stuff I thought.

It’s easy enough to determine if changes have been made, but I can’t work out how to go back, or resume if the user chooses CANCEL. The program exits anyway without my control.

This all happens in the Main Window, Close Event:

Dim result as Integer
Dim myMessage As String = "Do you want to Save the changes made in the SPECIFICATIONS panel?"
result = MsgBox (myMessage,51,"Impulse Recorder")
If result = 6 Then //YES Pressed
  HeaderFileWRITE // Write changes to Header Data File
End If
If result = 7 Then //NO Pressed
  // Do nothing and exit without saving changes
End If
If result = 2 Then //CANCEL Pressed
  Return // Return to the program and do nothing
End If

Intuitively I think it’s something to do the the “close” event - but I cannot see an alternative.

Help appreciated. Cheers.

Look at the CancelClose event.

You have to understand the CancelClose Event as a question. Like “Do you want the Window to really Close at it’s current state or do you want to Cancel this Close Event?”

F.e. you can ask your User in the CancelClose event the “Do you want to Save ‘Cancel, Yes, No’” Question and Return from CancelClose a “True” if you want to cancel the Close or a “False” if you want to let the Window close.

Thanks guys - that looks like what I was missing.

At the moment I don’t have the time to test but will do so as soon as I can - I’m sure it will be resolved.

A bunch of flowers and a bottle of well aged scotch to both of you.

Cheers :slight_smile:

[quote=347314:@Steve Kelepouris]A bunch of flowers and a bottle of well aged scotch to both of you.
and shipping from australia to germany :wink:

After fiddling around with some other conditions that had to be met first - this is working as expected.

I forgot about the cost of shipping - Oh well sorry guys, but it’s the thought that counts :slight_smile: