Solved

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

Posted on 2004-05-02
4
148 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
4 Comments
 
LVL 85

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Help with distributing .NET Framework with Clickonce technology 2 36
Programmatically signing Word macros 4 72
Help with Syntax 9 36
Help with AsEnumerable(), LINQ 4 39
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…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

805 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