detecting the file changed before saving it ?

A

Aurora

How can I detect that a filed has changed, a file that has not been saved
yet, so that in this case on form closing to pop up a message asking the
user
if they want to save the file before exiting the application ?
I mention that I was trying to use FileSystemWatcher but it is able to
detect the change after the file was saved which is not my case.

Thank in advance,
Aurora
 
C

Cor Ligthert[MVP]

Aurora,

Mostly "a file" that is used to be written at is read locked, therefore can
you give us an idea why that is not in this case?

(The construct row, but also the reason after this idea).

It seems to me like you write it now that you put the horse behind the cart.

Cor
 
M

Michel Posseth [MCP]

Hello Aurora


Perhaps simplest method is with a boolean flag ( eg a local variabel in the
form ) that keeps track of changes ( eg set the var ) and a save routine
that sets it to the opposite position , if the form is beeing closed you
check the flag , and perform the action as described by you

HTH

Michel Posseth
 
A

Aurora

Not at all ... I am trying to do what Microsoft Office does when you changed
a file and you forgot to save it.
On exit Office will ask you if you want to save it.

Aurora
 
F

Family Tree Mike

Aurora said:
Not at all ... I am trying to do what Microsoft Office does when you
changed a file and you forgot to save it.
On exit Office will ask you if you want to save it.

Aurora

Suppose in Office you created a "New" word document. It is not saved until
you hit the save button (or file-save menu item). If you quit before
typing, word doesn't ask if you want to save. It simply quits because you
haven't made any changes to what they consider a null document. As soon as
you type a character, the document is marked as "dirty". This flag is then
checked on exit to see if a save is needed. Further, if a user saves the
file during a session, the "dirty" flag should be set to false, as the file
is up to date. Then once again, as a character is typed, the document is
marked dirty.

The filesystemwatcher would only tell you if a file changed during an
application, but if your application is the one changing it, I don't see the
benefit.
 
J

John Simpson

Aurora said:
How can I detect that a filed has changed, a file that has not been saved
yet, so that in this case on form closing to pop up a message asking the
user
if they want to save the file before exiting the application ?
I mention that I was trying to use FileSystemWatcher but it is able to
detect the change after the file was saved which is not my case.

Thank in advance,
Aurora

If the file is not humungous then (aircode)
read the file into strFileBeginSession
make changes (or not)
Exit procedure:
read file into strFileAfterSession
if strFileBeginSession <> strFileAfterSession then
msgbox "Do You Want To Save Changes?"

I'm doing this with forms now -- should work OK with a file.

John
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top