-
Form Exiting
Hi Guys!
Question: I have the following code in my WordPad.
Code:
If bEdited = True Then
Dim check As MsgBoxResult
check = MsgBox("Text has not been saved. Save changes?", MsgBoxStyle.YesNo)
If check = MsgBoxResult.Yes Then
If tb1.Text <> "" Then
sfd.Filter = "Text Files (*.txt)|*.txt"
sfd.FilterIndex = 1
sfd.ShowDialog()
If sfd.FileName <> "" Then
FileOpen(1, sfd.FileName, OpenMode.Output)
PrintLine(1, tb1.Text)
FileClose(1)
Me.Text = sfd.FileName
End If
End If
End If
If check = MsgBoxResult.No Then
Application.Exit()
End If
End If
bEdited = False
Application.Exit()
This Code works OK but does not do what I would like it to do, as you can see it will bring up the save dialog any time something was changed. Now, if the user created a new file that would be acceptable, but if the user has made changes to an existing File it should only prompt (Yes/No) and if “Yes”save the File automatically.
How would I go about doing this??
Thanks!
-
What if you try having two boolen variables . One for new file creation and the other one for editing files . Then you would check for these values with two if blocks .
-
Hi,
"but if the user has made changes to an existing File it should only prompt (Yes/No) and if “Yes”save the File automatically.
How would I go about doing this??"
When the file is originally opened for editing, store the path (in a variable or textbox etc.) If it is a new file, make that variable (or etc.) blank. In your closing code check for the contents of that variable (or etc.) with another nested If clause and act accordingly, bypassing the FileSaveDialog box if necessary.
Hope that helps,
taxes.