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
Solved

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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
write xml in vb.net 2 32
VB.net capture  result of a SQL query in variables 3 20
Generate Unique ID in VB.NET 21 61
Get month and date in a format 4 31
This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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