Solved

Saving State

Posted on 2001-09-17
10
228 Views
Last Modified: 2010-05-02
In VB, how do do I save the state of a form?  For example, I have several forms that a user can progress through.  The problem I am having is when the user clicks 'Cancel' on a particular screen.  When this happens I want to redisplay the previous screen with all the same settings the user selected.  Currently, I am using the registry to keep track of state information.  Is this the best way?  What are my options?  Some example code or internet documentation would be very helpful.  Thanks.
0
Comment
Question by:hotwheels
  • 3
  • 2
  • 2
  • +3
10 Comments
 
LVL 2

Expert Comment

by:telebasics
ID: 6487794
The registry is NOT the place to keep track of selected values, use variables, Whe are talking VB right not ASP webpages? If VB it is, you can easely collect the selected info in global variables of your main form.

An other option is to make all form layouts in the same form and then hide/display the right layout while progressing, this way you only have to collect the info at the end, and all settings are maintained until the user closes the form or clicks the final finish button.

This sollution, is more design intensive but much neater then yours, and it is how setup forms (tab forms) work
0
 
LVL 5

Expert Comment

by:rkot2000
ID: 6487798
can you use form.visible = false to hide previous screens?
and form.visible = true to show
0
 
LVL 3

Expert Comment

by:Diveblue
ID: 6487874
rkot2000 has the better answer here. Global variales are generally discouraged if you can use a lesser scope to do the job (ie form or procedure level variables) Simply hiding a form will retain all listbox selections, textbox valus, etc. They'll still be there when you show the form again. If you're holding info in form level variables, be aware of this:

If you use syntax like
form1.Show
'set some form level vars
''''more stuff
unload form1

when you do a form1.show again, he form level vars will still hold the vals you set before you unloaded (sounds like you may want to use this to your advantage)


in contrast, the following will not retain values from myform.show to the next.


Dim myForm as form1
Set myForm = new Form1
myForm.Show

'set vals
unload myform

Set myForm = new Form1
myForm.Show
0
Technology Partners: 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!

 
LVL 4

Expert Comment

by:amit_panjwani
ID: 6488001
hotwheels,

Firstly , Storing settings in registry may be right choice if no of settings is limited.

By the way - do you want values to persist even when user has closed application ?

or Is it that you just want to maintain state for current session ?

Amit
0
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 6489286
Hi hotwheels,

Depends on what you need in your application.

Keeping the values in registry is a choice, alternatively you can also store the values in a INI file, or use a normal file that you can define the method to read/ write from it.

Using registry is good as its location never changed.

regards.
0
 
LVL 2

Expert Comment

by:telebasics
ID: 6489897
Use the registry only for settings you want to maintain even after software is close, pc is rebootde, etc. but for a current sellection, and therefor var's wich are only used temperorly and is not the right way to go.

I agree with rkot2000 as it is like i stated as seconde and more preferable sollution in my first post, hiding/showing layouts is better.
0
 
LVL 51

Expert Comment

by:Ryan Chong
ID: 6490045
> hiding/showing layouts is better
Only when few forms are loaded or in a small application bcos memory will be loaded as forms are loaded..
0
 
LVL 2

Accepted Solution

by:
telebasics earned 75 total points
ID: 6490094
well, these are the sollutions, looks like it is a personal choice what is better, i personaly try to keep the registry as clean as i can.

btw, you can use multiple "forms" in one form object, like using the tab control, on form holds many, wich all get hidden and only the one you want to show gets shown, one piece of memory, and when your totaly done unload the form and memory is free, dont forget to save ;-)
0
 

Author Comment

by:hotwheels
ID: 6490798
All of these suggestions are great!  I am real busy right now, and it will take me some time to test out the solutions.  I only need the variables during the current session.  However, the memory use is a large factor.  Thank you all very much for your comments.  I will assign points within two weeks.
0
 
LVL 4

Expert Comment

by:amit_panjwani
ID: 6490903
Hotwheels

If you need to save state for current session,then you might like to add properties to FORM, similar to classes Let/Get


Hope this Helps
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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
Windows Script Host failed (Access is denied.) error 6 323
Copy a row 12 69
Problem to With line 4 74
How to read File Date Created using VB6 8 61
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

763 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