Solved

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

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 exporting to excel 4 44
FInd Image Control Gridview 3 35
Convert Ctime to date time in textfile? 7 62
VB.NET System.NullReferenceException 1 18
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…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…

735 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