Solved

Check status of a file, has been save or not ?

Posted on 2004-05-02
4
152 Views
Last Modified: 2010-04-24
I wrote an application same as NotePad. How can i check a text file has been modified and must be save before closing it (a nsgbox to confirm).
0
Comment
Question by:tipt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 63 total points
ID: 10972812
Basically you need to set a boolean flag that is set to false when you first create or open a file.  Then whenever the user does something to change the contents as the file such as pressing a key in the edit area or pasting something into the edit area, set the boolean flag to true.

Now when the form is closing you can check the status of that boolen flag and ask the user if they want to save changes or not.  Your code would be very similar to this:

    Private Sub frmGlossaryEditor_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
        If changed AndAlso MsgBox("Would you like to save those changes?", MsgBoxStyle.Question Or MsgBoxStyle.YesNo, "Unsaved Changes have been made to this Glossary") = MsgBoxResult.Yes Then
            ' Call your saving subroutine here....
            saveGlossary_Click(Nothing, Nothing)
        End If
    End Sub

Idle_Mind
0
 
LVL 4

Assisted Solution

by:rehand
rehand earned 62 total points
ID: 10980931
What idle has propose is a common practice, and you will see it refered to often as the IsDirty method. I have seen and implemented it in two ways.

1) create and blnIsDirty variable and set it to true if the user makes changes.
2) Do binary comparison on the two files to see if there is a difference.

The reason for the two methods is that sometimes there are too many was to make a file "dirty" and it is often easier to create class which will compare two files and determine the dirty status.

Review:

Method 1)
Pros:
Easy to implement if there are only a couple of ways a user can change a file.

Cons:
Requires that you update the blnIsDirty variable any time the user makes a change.
May require a save even if no changes were made. (i.e user types a space and then undoes the change.

Method 2)
Pros:
Single reusable method that only needs to be called once.

Cons:
Requires that you write a binary file comparison class.

0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

631 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question