*Experts* DiverDan Posted February 12, 2003 *Experts* Posted February 12, 2003 (edited) Hi, I'm calling a checkSave sub prior to the closing of Form1. The checkSave sub creates a yes, no, cancel message box and from the button selection sets a boolean value on varaible continue. Code is: Sub checkSave() If worksheetModified = True Then Dim responce As MsgBoxResult responce = MsgBox("Do you want to save changes to " & StatusWorksheet.Text & " ?", MsgBoxStyle.YesNoCancel, Me.Text) If responce = MsgBoxResult.Cancel Then continue = False ElseIf responce = MsgBoxResult.No Then worksheetModified = False continue = True ElseIf responce = MsgBoxResult.Yes Then mnuSaveAs.PerformClick() worksheetModified = False continue = True End If End If End Sub This works well with every part of the program except for the Form1 close button "X". I wrote a closing sub for Form1 closing with the code: Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing checkSave() If continue = False Then Exit Sub If continue = True Then MyBase.Dispose() End Sub The problem is that the form closes when the message box cancel button is chosen and continue = False. Why? Thanks Edited February 12, 2003 by Robby Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
*Experts* Volte Posted February 12, 2003 *Experts* Posted February 12, 2003 Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing If continue = False Then e.Cancel = True Else Me.Dispose() End If End Sub You need to set e.Cancel = True to make it stop closing. Quote
Moderators Robby Posted February 12, 2003 Moderators Posted February 12, 2003 AS a side note.... I noticed you're using lots of member variables, you can eliminate continue by doing this... Function checkSave() as boolean If worksheetModified = True Then Dim responce As MsgBoxResult responce = MsgBox("Do you want to save changes to " & StatusWorksheet.Text & " ?", MsgBoxStyle.YesNoCancel, Me.Text) If responce = MsgBoxResult.Cancel Then return False ElseIf responce = MsgBoxResult.No Then worksheetModified = False return True ElseIf responce = MsgBoxResult.Yes Then mnuSaveAs.PerformClick() worksheetModified = False return True End If End If End Sub Private Sub Form1_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing If not checkSave Then e.Cancel = True Else Me.Dispose() End If End Sub Quote Visit...Bassic Software
Heiko Posted February 12, 2003 Posted February 12, 2003 And then give a more meaningful name to the function and I'll be happy, too :-) Quote .nerd
Moderators Robby Posted February 12, 2003 Moderators Posted February 12, 2003 You can name it whatever you want... SafeToExit or IsSaved Quote Visit...Bassic Software
*Experts* DiverDan Posted February 12, 2003 Author *Experts* Posted February 12, 2003 Thanks to you all... Learning VB.net is definately an ongoing process for me. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
Moderators Robby Posted February 13, 2003 Moderators Posted February 13, 2003 For me too. Quote Visit...Bassic Software
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.