reconrey Posted February 25, 2010 Posted February 25, 2010 (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 February 25, 2010 by PlausiblyDamp Quote
Administrators PlausiblyDamp Posted February 25, 2010 Administrators Posted February 25, 2010 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Leaders snarfblam Posted February 25, 2010 Leaders Posted February 25, 2010 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. Quote [sIGPIC]e[/sIGPIC]
reconrey Posted February 25, 2010 Author Posted February 25, 2010 so would the boolean be safer? more relaible? Quote
Administrators PlausiblyDamp Posted February 26, 2010 Administrators Posted February 26, 2010 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. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
reconrey Posted February 26, 2010 Author Posted February 26, 2010 ok...i think i will use a boolean then :D it would go sumthin like this right? Private Declare Function Saved as Boolean = True Quote
reconrey Posted February 26, 2010 Author Posted February 26, 2010 nvm it'd be: Dim Saved as Boolean = True Quote
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.