Home > Articles > Web Services > XML

Where Was I? Restoring Application State with VB and XML

  • Print
  • + Share This
In many of the more complex applications, users spend considerable time and energy getting started in the morning. You can make all this easier by giving an application the capability to remember where it was when it last exited. This article shows you how to use XML to save an application's session state so users can pick up where they left off.
From the author of

Consider the customer contact application shown in Figure 1, and imagine how you might use this program if you were a billing representative. You start the application, make it fill half of the screen and then place Outlook, an accounts receivable system, FreeCell, and other miscellaneous programs on the rest of the screen. You select the Windows menu's Customers command to pull up a Customer List form. Using the fields on the top of this form, you select customers with accounts that have active statuses, unpaid balances greater than $50, and last billing dates more than 30 days ago. In a more database-transparent system, you might even directly enter the following query:

SELECT * FROM Customers
WHERE Status='Active'
 AND Balance > 50
 AND DaysUnpaid > 30

Figure 1 Users can spend a considerable amount of time preparing a complex application for use each day.

You click on List, and the program displays a list of customer accounts that need attention. You double-click on a list entry to see the detailed record for that customer, and finally get to work.

This whole setup process may only take a few minutes each day, but that time adds up. It's also downright annoying. Ideally, an application accommodates the user, not the other way around. The program seems so intuitive that at the end of the day, you feel you have done your job, not spent eight hours indulging a piece of software. Making you spend this extra setup time each morning doesn't help maintain your illusion of control.

A much worse problem is that all this setup forces you to think about arranging windows and entering search criteria when you should be thinking about doing your job.

Session State

A program's session state is its current state of affairs. It includes the forms that are visible and their positions, any options the user has set, values in text boxes and option buttons, and so forth. A complete session state represents every piece of data currently in use by the program.

An application can help the user pick up exactly where he left off by saving its session state. When it starts, the program reads the saved state and sets all of its forms, text boxes, initial dialog directories, and other day-to-day work-related values back to their previous values.

Saving the program's session state isn't a difficult concept, but many programs don't bother. That's reasonable for a limited-feature program such as Notepad. It's annoying when a complex and expensive application doesn't save this information. For example, whenever I start Microsoft Word, it resets its file open dialog box to My Documents. I store my documents with their projects, not in a centralized My Documents folder so this is never the correct choice. Word could make my life a little easier if it remembered where I was working the last time I used it.

Program Restore, shown in Figure 1, saves and restores its session state. When you invoke the Windows menu's Save Session command, the program saves size and position information about the main form, the Customer List form, and the Employee List form. The program also saves the values selected in the list forms' combo boxes and the values entered in their text boxes.

When you start the program, it reloads its most recently saved settings. After working with the program, possibly closing list forms and opening others, you can invoke the Windows menu's Restore Saved Session command to restore the settings to their saved values.

  • + Share This
  • 🔖 Save To Your Account