Solved

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

Posted on 2004-05-02
4
146 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now