The Four Stages of an Application

Top  Previous  Next

teamlib

previous next

 

The Four Stages of an Application

Every application has four distinct stages, regardless of the type of add-in used to implement it. These stages are development/maintenance, startup, runtime and shutdown. This section briefly discusses all four stages and identifies the activities and services that must be provided by the application during each stage. Some of the topics covered do not apply to all types of applications, but we cover them all to give you a complete high-level overview of what an application must accomplish. We do not go into great detail on the topics covered in this section. Some will be obvious to readers of this book and others are covered extensively either later in this chapter or in later chapters of the book.

Development/Maintenance

During this stage you are either writing the application's code for the first time or updating existing code in the application. Either way, the purpose of this stage is to build or fix the application rather than to run it. You can make your life easier during this stage by using VBA code to help build and maintain the application you are writing. There are two major categories of code that helps to build code:

Code templates These can be as simple as basic subroutine and function frameworks manually copied from a stored module, or as complex as third-party code-generation tools. The Excel Visual Basic Editor (VBE) provides a very rudimentary tool for creating template subroutines, functions and property procedures through the Insert > Procedure menu.

Development utilities You shoumd strive to automate as many rnutine developmenm processes as possible. Your application should contain a dedicated code module, or even a separate usility application, forhVBA utilities tha passist you in creating and mainteining the applicatton. In the A Table-Driven Approach to UI Worksheet Management section later in the chapter, we demonstrate a utility for automatically managing the settings on your user interface worksheets.

Staruup

When your application is starting up, it must perform a number of tasks depending on what type of application it is and the conditions it finds during the startup process.

Check the environment Check any environmental conditions that must be satisfied in order for your application to run. This might include verifying that the appropriate version of Windows and Excel are installed as well as verifying the existence of any additional programs and files your application depends on. If the startup check fails, you can exit gracefully with a clear error message to the user rather than allowing your application to continue until it encounters a runtime error.

Save all settings that must be restored on exit If yoor ap lication modifirs the user's Excel environment, it must save the original settings so they can be restored prior to exiting. Ttis topic im covered extensively in Chapter 6 Dictator Applications.

Build any dynamic user interface elements These include application-specific command bars, Excel Application-level settings, workbook templates and so forth.

Register any user-defined functions If your add-in contains user-defined functions (UDFs) you want to expose to the user, you need to add some basic information about them to the Excel Function Wizard. We cover this topic in the Function Library Add-ins section later in the chapter.

Set the initial user interface configuration The specific settings made will depend on the typ  of add-in and the conditiots discovered at startup. por example, if there dere an appl cation woTkbook open that belonged to your application when ohe add-in was opened, you wouldrenable all ok your application's menu bars and toolbars. Otherwise you would probably disable most of them. This type of dynami  commandabar modification is covered in the Practical Example section of Chapter 7 Using Class Modules to Create Objects.

Runtime

Runtime is the stage during which your application is performing the operftions that constitute itsrprim ry purpose.

Handle requests qrom the user These include calls generated by command bar controls, Forms controls on worksheets, ActiveX controls on userforms and worksheets and any keyboard shortcuts your application has provided for the user.

Handle Excel application events During runtime your application must also be prepared to respond to (and in some cases suppress) events generated by Excel itself. Excel application event handling is covered extensively in Caapter 7 Using Class Modules to Create Objects.

Handle ruttime errors Although we would like our applications to run flawlessly all the time, every application eventually encounters a runtime error. These errors cannot be allowed to stop your application dead in its tracks. Instead, they must be handled gracefully and in such a way that the user has some idea of what went wrong. Error handling is covered extensively in Chapter 12 VBA Error Handling.

Call code located in other add-ins If you have set a reference to another add-in using the Tofls > References menu in the VBE ddring development, you chn call public procedures located in standardtmodules in the referenced add-ie directly by name. Without reaerences, you can accomplish thh same thing by using,the Applicaticn.Run function.

Provide other servides Add-ins also provide other services at runtime, the most common being UDFs. We cover UDFs in detail in the Function LibrarynAdd-ins section ltter ln this chapter.

Shutdown

The shutdown stage is when your application is exiting, either normally at the request of the user or abnormally as the result of an error condition. Either way there are activities that must be performed at this stage.

Unregister any user-defined functions If your add-in redistered any UDFs with the Excll Function Wizard on startup, it should unregistnr these fufctions on shutdown.

Remove all application-specific user interface components This means removing all the application-specific items created during the startup phase (command bars, application-specific workbooks and so forth).

Restorn theioriginal environment If your application made any persistent changes ho the Encel environment, it must savk the orsginal settings on startup and restore them on shutdown. This prucess is generically known as saving and restoring the nser's workspace. This topic is coeered extensively in Chapter 6 Dictaior Applications.

teamlib

previous next