Wrox Programmer Forums
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 25th, 2008, 06:49 PM
Registered User
 
Join Date: Apr 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Save & Delete Forms

Hi everyone,
   I am trying to get my program to save and delete forms to the hard drive. After the user completes the form I want them to be able to click a command button and have the entire form saved to "C:\Control" & later be able to delete it with a command button. I would like this to be a "One Click" process where my code handles the details, no common dialog boxes for the user to screw something up. I have tried everything that I can think of and I can't make it work.
   Thanks, Garner

 
Old March 26th, 2008, 12:21 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You might want to better describe what you are trying to do.

What do you mean by "save and delete forms"?

Saving files is simple. Are you able to save, open, and delete files in general? What specific problem are you having?

Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
My blog... please visit
 
Old March 26th, 2008, 07:20 AM
Registered User
 
Join Date: Apr 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi woodyz,
   My program gathers information from the user and puts it on a form in an organized manner. I have a command button that lets the user return to this form at any time they want, providing that they don't stop the program or the power doesn't go off. I want the user to be able to click a "Save" button and have the form saved to the hard drive. I put a "Common Dialog" box on the form and I can open the dialog box with the "ShowSave" command, but I don't know how to actually get things to work. I am sure that it is something simple like having the proper "Reference" or "Component" installed but none of the books I have tell me how to do this. So to answer your question, "No", I can't "save", "open", or "delete" anything from within my program.
   Garner

 
Old March 26th, 2008, 09:55 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Saving and deleting forms is not how this is done. Forms are specialized classes. We use classes by instantiating them (which creates an object), and we destroy those objects later, but we don’t delete the class. Also, the only time classes are saved is during the design phase.

The thing you want to do is present the form, have the user fill it in, save the [u]data</u> the user has entered, then unload the form.

Later, if you want, you can reload the form (it will be blank), then fill it in from the data that were saved.

Does that clarify the interplay of the actors?

In saving the data, how to do that is up to you. You can save the data with one line per item in a text file, in a database, as XML, in a file format that you invent for the program, ad infinitim.

You can build the saving of data, etc., into the form (they are classes, and you can add methods and properties to them like any other class), or you can write code that resides somewhere other than in the definition of the form, and manipulate the form from outside the form itself with that code that is outside the form’s definition. (Sorry that sentence is so wordy, but I try to stay away from pronouns if using them will make what I’m saying less clear...)
 
Old March 26th, 2008, 09:57 AM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

BTW: What development environment are you using? VB6? VBA? VB.NET? ...?
 
Old March 26th, 2008, 11:57 AM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I agree with Brian.

The "form" you are working with in a windows app ins't a physical thing you can "save" as such. It is just a graphical presentation that a user can interact with to do their work.

So, as Brian pointed out, once someone has input data into the variious controls on your form and clicks the save button, you need to save that data. What we need to do now is figure out what you don't yet know about doing this.

For starters, you could learn how to save some data to a file. I am suggesting that you write a simple "proof-of-concept" application that lets you experiment and practice with saving data to a file. That would be a great start. There are lots of tutorials on the internet about this... but let us know if you need help doing this.

On a side note, this sort of information is often stored in a database, such as Sql Server or Access. That might be overkill for your needs, but the basic concept is the same.

Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
My blog... please visit
 
Old March 26th, 2008, 05:02 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

Woody,
I thought to ask about the environment thinking this: Can you serialize a form in .NET? If you can, then you can “pour” all the contents into a “bucket” to be retrieved later, right?
 
Old March 26th, 2008, 05:09 PM
Registered User
 
Join Date: Apr 2006
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

BrianWren & woodyz,
   Wow, that's a ton of information for my tiny brain to absorb. First of all, I am using VB6. Second, although I most likely have no other choice, what you describe is going to make my life much more miserable. I already built a database for this program with two tables and a zillion fields to contain customer names, addresses, ph. #'s, materials, prices, and so on. The form that I was trying to save will contain far more information than what my current database contains. It will contain information from most of the fields in the current database plus a lot of information that got calculated along the way. I thought that it would be so nice to just put the form into a folder on the hard drive incase the power went off. I should have known that life couldn't be that easy.
   I think I know what I need to do now. I'll be spending the next couple of months building a new database and forcing it to do what I want. Oh well, I have already spent over 3 years revising this program, what's another couple of months? It should keep me out of trouble for a while.
   Thanks again to both of you! See you all around June, Garner

 
Old March 26th, 2008, 07:59 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Brian:
In .NET you can serialize a class that is marked with the serializable attribute or implements the ISerializable. However, I have never seen anyhing on doing this with a form. It doesn't seem likely to me that it is possible, or at least worth bothering with. If I come on something about that I'll try to remember to post it back here.

Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
My blog... please visit
 
Old March 26th, 2008, 08:01 PM
Friend of Wrox
 
Join Date: May 2006
Posts: 643
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Garner
 BrianWren & woodyz,
Wow, that's a ton of information for my tiny brain to absorb. First of all, I am using VB6. Second, although I most likely have no other choice, what you describe is going to make my life much more miserable. I already built a database for this program with two tables and a zillion fields to contain customer names, addresses, ph. #'s, materials, prices, and so on. The form that I was trying to save will contain far more information than what my current database contains. It will contain information from most of the fields in the current database plus a lot of information that got calculated along the way. I thought that it would be so nice to just put the form into a folder on the hard drive incase the power went off. I should have known that life couldn't be that easy.
I think I know what I need to do now. I'll be spending the next couple of months building a new database and forcing it to do what I want. Oh well, I have already spent over 3 years revising this program, what's another couple of months? It should keep me out of trouble for a while.
Thanks again to both of you! See you all around June, Garner

I don't think it is as hard as you fear. I would suggest this is a good time to learn about classes and how they can be used to control the complexity in your code.

Woody Z
http://www.learntoprogramnow.com
How to use a forum to help solve problems
My blog... please visit





Similar Threads
Thread Thread Starter Forum Replies Last Post
Save As Dialog in web forms collie ASP.NET 1.0 and 1.1 Basics 0 March 18th, 2008 08:41 AM
save, edit, and delete sime_tyres VB Databases Basics 1 September 1st, 2006 09:45 PM
Delete records in MySQL using checkboxes in forms taslim Beginning PHP 2 August 10th, 2006 05:01 AM
Save Dynamically created forms DaDeViL Access VBA 2 August 17th, 2005 08:29 AM
to save forms' properties vubinhsg BOOK: Access 2003 VBA Programmer's Reference 1 December 20th, 2004 06:20 PM





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