p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Visual Basic 2012 Programmer's Reference (http://p2p.wrox.com/forumdisplay.php?f=694)
-   -   Properly closing a file (http://p2p.wrox.com/showthread.php?t=88781)

Gary108 November 9th, 2012 06:21 PM

Properly closing a file
 
Hi Rod,

It's been a long time since I checked in with you. When I was writing to you before one of my questions was how to save the contents in a TreeView box so that it could be reloaded later on. This would be for a situation in which the user creates the TreeView List while running the program (not written into the code). You gave me some ideas and I finally was able to do it. I can create the list in TreeView, Edit, Save it and Open it.

There is only one problem left that stumps me. As long as I close out the application completely before I open a file there is no problem. However, it seems to me that I should be able to work with a file, close the file and open it again without closing the entire application. Just like in Microsoft Word, you can open a file or start a new one, edit it, and close the file without leaving MicroSoft Word.

I assume that even though I clear all of the Text Boxes, TreeView Box, List Boxes and so on, so that everything looks like it did before I opened the file, there must be something in the code that is not going back to its previous state. Otherwise, why do I get a different result when I open a file immediately after starting the application than I do when I open a file after saving it and without leaving the application?

I would appreciate Any insight you can give me in this connection.

Sincerely,


Gary

Rod Stephens May 20th, 2013 11:16 AM

Sorry for the long delay. I didn't see this post.

Quote:

There is only one problem left that stumps me. As long as I close out the application completely before I open a file there is no problem. However, it seems to me that I should be able to work with a file, close the file and open it again without closing the entire application. Just like in Microsoft Word, you can open a file or start a new one, edit it, and close the file without leaving MicroSoft Word.

I assume that even though I clear all of the Text Boxes, TreeView Box, List Boxes and so on, so that everything looks like it did before I opened the file, there must be something in the code that is not going back to its previous state. Otherwise, why do I get a different result when I open a file immediately after starting the application than I do when I open a file after saving it and without leaving the application?
How is the file different?

If you write into a file, the text may not actually be written to the disk right away. Instead the system may buffer the data and then write it later when the buffer is full. This is more efficient than writing the data immediately because that would force the program to wait for the relatively slow disk drive.

All this means if the program crashes or exits without flushing or closing the file, some of the data you wanted to write into it may be lost.

So the program should always close the file before exiting.

If you close and reopen the file, it should look the same as if the program had closed and then restarted.

I hope that help. Sorry again for the long delay.


All times are GMT -4. The time now is 10:42 PM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.