Jump to content
Xtreme .Net Talk

Recommended Posts

Posted (edited)

Well im wondering how to make my text editor ask to save the changes before closing, what i mean is if you changed the document it will have a message box if it has been saved after changens, i know i can do:

Dim SaveSts as String = "Saved"
'Under TextBox1_TextChanged:
SaveSts = "Unsaved"
'Under Savebtn_Click:
SaveSts = "Saved"
'Under Form1_FormClosing:
'use e.cancel  = true and a msgbox

Is there a better way of doing this?

Edited by PlausiblyDamp
  • Administrators
Posted

Other than the fact I would use a boolean rather than a string to track if the file has been saved or not your method looks fine to me.

 

I am assuming you are going to use the MessageBox to prompt them to save / cancel and then set e.Handled accordingly.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

  • Leaders
Posted

Personally, my preferred method is to store a copy of the original document (in memory) and compare it to the current version of the document. You might find yourself in a situation where the document might be larger that something you would like to keep in RAM. In that case you could consider storing a hash of the original document and comparing it to a hash of the current document.

 

PD is right, though. In this simple case, your method should work fine. In some situations there may be many places in the UI where the document can be modified in different ways. Being able to compare to the saved version of the document seems to cover all bases.

[sIGPIC]e[/sIGPIC]
  • Administrators
Posted

A boolean is a simple true or false option and in your situation a document has either been modified since the last save or not - to me a boolean seems the natural choice to represent this quality.

 

A string would require more memory than a boolean and is susceptible to spelling mistakes and typos with no compiler validation while a boolean prevents this kind of issue.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...