Hour 37


During this hour you will learn

Packaging Your Application

You've created, tested, and debugged your application. The final step is packaging your application for distribution to others. If you're creating the application for yourself, you'll probably just compile the application and copy the compiled application and its support files to the folder from where you want to run the program. You can use the Start menu's Settings, Taskbar option to hook the application to your Start menu.

If you want others to use your application, you need to automate the installation so that all the project's files get to their proper location and the Start menu gets the option your program needs. This hour's lesson explains how to distribute the application by using the Visual Basic Scheduler as a guide.

Compiling the Application

Visual Basic makes compiling your application simple. The compiled file is a final executable .exe file. All the related modules and forms work together to form the executable file. Although auxiliary files might still be necessary, such as a Microsoft Access database file used for initial data, most of your project's files combine into the executable to make distribution easier.

The compiled application is more secure than a distributed source project. If you distribute the source code (the project and its related files), anyone with Visual Basic can modify your work. However, most people can't even run your program because they don't have Visual Basic to load and run the program. Therefore, a compiled file is necessary for normal distribution.

Your compiled application runs much faster than the application running within VB's development environment. You want your application to run as quickly and smoothly as possible without your users doing more than necessary. The compiled executable file makes the application's execution simple.

Before you compile your application, make sure that you've debugged the application as much as is feasible and that you've eliminated as many bugs as possible. You can't debug compiled applications with the VB debugger because you run compiled applications from outside the Visual Basic development environment.

When you're satisfied that you have your program running as accurately as possible, choose Make from the File menu. Visual Basic displays Figure 37.1's Make Project dialog box. Select the folder where you want to store the compiled application. (Visual Basic uses the project name as the default executable name.)

FIG. 37.1

You compile the program from the Make Project dialog box.

Before clicking OK to start the compilation, click the Options button to display Figure 37.2's Project Properties dialog box. (You access this dialog box by choosing Properties from the Project menu.) The version number and information let you specify version information for the compiled application. If you plan to release several versions of the software, the version numbers let you determine the order of versions. You can specify the version information from the development environment's Project Properties dialog box so that you don't have to specify versions just at compile time. The version numbers and description information stay with the project's source code.

FIG. 37.2

Set the compiled project's options in the Project Properties dialog box.

The Icon entry designates the icon that indicates the application on the Windows Start menu and on a taskbar button. Generally, you leave the primary form name in the Icon area. The form's Properties window contains an Icon entry from which you can select an icon for the form and, therefore, for the compiled application.

Click the Compile tab to display the Compile options page (see Figure 37.3). To optimize the compiled project to make it run as quickly as possible, leave the Compile to Native Code option selected. (If you compile to p-code, or pseudocode, the application requires that your users keep a runtime VB-based .DLL file in their Systems folder. Native code runs faster and requires fewer files.)

FIG. 37.3

Specify the compile options on the Compile page.

If you select any of the options that appear when you click the Advanced Optimizations button, you forsake some of the runtime error checking but gain execution speed.

When you close the options dialog box and click OK, Visual Basic compiles your code. Assuming that no compile errors exist, Visual Basic creates the .exe file (you'll see the compilation status in the upper-right corner). You can exit Visual Basic and run the application by selecting the Start menu's Run option. The form's icon that you selected appears in the taskbar when you run the program.

The Application Setup Wizard

The Application Setup Wizard does a lot of work for you, including the following:

The Application Setup Wizard generates a list of several files needed for the setup. A single Setup.exe doesn't come out of the setup routine. Often, a Visual Basic application requires .dll and .ocx files, and those files reside in targeted setup area (floppy disks or a hard disk) with the compiled program and the Setup.exe program.

The Application Setup Wizard isn't part of VB's development environment. You need to start the Application Setup Wizard from the Start menu. Use the same Start menu option from where you start Visual Basic and select the Application Setup Wizard to run the program and display the wizard's opening dialog box (see Figure 37.4).

FIG. 37.4

Start creating the setup program from the opening Application Setup Wizard dialog box.

The Application Setup Wizard creates a template file that describes the setup routine. In subsequent sessions, you can either modify a setup template that you've already created before, or create the setup from the original project. Therefore, you must select the project or template file from the Application Setup Wizard's second dialog box (see Figure 37.5) so that Visual Basic knows what to set up. Template files end with the .swt file-name extension; previous Visual Basic setup files that used the .vbz extension aren't compatible with version 5 and later. If you want to follow along, select the Visual Basic Scheduler application (click Browse to locate the file).

If you want to set up an ActiveX control, be sure to mark theGenerate Dependency File check box so that the wizard can collect the proper files in the order needed. Also, if your application uses DAO commands, as the Visual Basic Scheduler does, you need to request dependent information.

FIG. 37.5

Select the project and options to set up.

Most of the time, you use the default option, Create a Setup Program, to generate a regular setup program that your users can run to install your application. If your application contains special .ocx ActiveX controls that don't normally appear in the standard Toolbox, you might want to add the dependency information so that the setup routine locates the ActiveX controls properly. Or you can select Create Internet Download Setup to create an Internet-based installation program, or you can create a dependency file only.

Click Next to show Figure 37.6's dialog box, which requests distribution information. The Application Setup Wizard needs to know where your final setup application should go.

FIG. 37.6

Specify the target for the setup files.

If you select the Disk Directories option, the wizard creates multiple disk folders as though they were floppy disks and stores the floppy disk image files in each folder. You can then create floppy disks from the separate folders.

Click Next to specify the location of the setup (such as the directory where you want the setup to go). If you install to a single directory, Visual Basic uses the default name of SWSETUP located beneath your Windows temporary directory, but you can select a different directory.

The directory you select should be empty. Therefore, you'll know, when the wizard finishes, that all the files in that directory are there as the result of the wizard. When you click Next, the wizard scans your project file to determine which program files your application needs. The wizard can't determine which database drivers are needed if your application contains any data-related control. You will see Figure 37.7's dialog box if your application requires database access.

FIG. 37.7

You must manually choose the proper data access.

If your application uses a Data control that works with a Microsoft Access database, you need to make sure only that the dbUseJet option is set. Microsoft Access requires the Jet Database Engine, which provides the necessary information for Microsoft Access work. Click the Jet 2.X option that appears in the list only if you use an older version of the Jet database engine (used in versions 3 and 4 of Visual Basic as well as Microsoft Access 2.0).

Click Next to move to Figure 37.8's ActiveX Server Components dialog box. If your application requires any ActiveX server components, the wizard lists those components. Also, if your application requires any ActiveX controls not found by the wizard and listed in the dialog box, you need to click Add Local (if located on your system) or Add Remote to locate the ActiveX controls and add them to the list. (This list forms part of the dependency list needed by some applications that you set up for installation.)

FIG. 37.8

Locate ActiveX controls, if needed.

When you click Next, the wizard displays a list of the dependent files, including your original project and any ActiveX controls it requires. Also, you see data-access files needed for the project if your application uses database commands such as the DAO routines.

You might not always have the proper license authority to distribute ActiveX controls unless you created those controls yourself. Therefore, consult your ActiveX control vendor to learn the rules under which you can distribute the controls.

When you click Next again, the wizard collects all the application's files together that you've specified and displays the final dialog box shown in Figure 37.9. Make sure that you look through the files to determine that every file is listed that your application requires. You might need to add (by clickingAdd) additional files, such as Readme.txt or a database file. If you're following this lesson by using the Visual Basic Scheduler, add the VBSched.mdb database file to the file list so that the installation routine stores the sample database file along with the installation files.

FIG. 37.9

The files are prepared for collection into the final setup program.

Click the Summary Details button to learn how much disk space your final application will consume after users run the setup program you're about to create.

When you click Next again, the wizard displays its final dialog box, letting you know that the setup information is gathered and that you can click Finish to create the setup program. If you click the Save Template button, the wizard lets you specify a template file name and saves a template with the setup program. You can, in subsequent Application Setup Wizard sessions, load the template and change the options if you ever need to change the type of setup you want.

If you don't save the template file, you can run the wizard in future sessions and create the setup again or with different options, but you have to specify all the setup parameters again. The template keeps you from having to specify every setup option for the same application in subsequent sessions.

After Generating Setup

After the wizard generates the setup routine, test the routine. To test the routine, run the generated setup program to make sure that no bugs appear and the final application runs smoothly on the computer.

If you really want to test the setup routine, run the setup program on a computer that has never contained your application. Even better, make sure that the computer doesn't even have a copy of Visual Basic installed. By testing your application on such a clean machine, you help ensure that your application installs properly on users' computers.

The Application Setup Wizard creates the setup files in the location you specified during the setup process. If you generated the setup files in a single test directory, you'll find the Setup.exe file among several other files whose file name extensions end with an underscore (_). The files with the shortened extension are compressed; the Setup.exe routine expands those compressed files onto the target machine or location.

The simplest way to test the generated setup routine is to chooseRun from the Start menu and find the Setup.exe file. Click the Run button to start the application's setup. Figure 37.10 shows the opening dialog box that greets you.

FIG. 37.10

Setup warns you to close all running programs before continuing.

If you cancel the setup program at any time before it completes, it closes after removing any files copied to that point. Therefore, if you cancel the process at any time, setup removes all traces of the application's setup.

After you click OK, the setup program needs to know where you want the installed software to go. Click the Change Directory command button if you want to change the path from the default path offered by setup. The default path is a folder with the application's executable name inside the Program Files folder. Any ActiveX controls that the setup installs go to your \Windows\System folder.

If you specify an installation directory folder that doesn't exist, setup asks whether you want to create that folder or select another one. Most of the time, you create a new one for the installation target folder.

After you change the installation folder or accept the default folder, click the large application installation button to begin setup. Generally, the setup doesn't take a long time if you set up from a hard disk. If the target is floppy disks, however, the setup takes longer and you'll probably have to swap disks.

Assuming that everything worked well, Figure 37.11 appears to let you know that the installation went well. Click OK to return to Windows.

FIG. 37.11

Setup is finished, so now you can test the application.

Setup uses a smart copy routine to copy files to the installation computer. If setup detects files on the target machine that have the same location and file name as a file about to be installed, and if the target machine's file is newer than setup's, the setup program asks users for permission before overwriting the newer file with the older setup file. Therefore, your users can safeguard against overwriting system ActiveX controls that might be updated and newer versions from your application's.

Changing the Setup Wizard

If you don't like the way the Application Setup Wizard operates, you can change it. The wizard actually runs a Visual Basic project that performs the setup. Microsoft supplies the project's source code, and you can edit the source code to change the way setup operates. To load the wizard's source code, you must open the project named Setup1.vbp that you can find in your \VB\setupkit\setup1 folder. In the setup project, you can find all of setup's forms, controls, and code modules.

Consider backing up the setup1 folder before modifying the wizard, in case you inadvertently change something you shouldn't. You can then restore from the backup, if you need to.

The setup source code is called the setup toolkit. The source code isn't the wizard's source code, but the wizard does use the code and forms in the final generated setup files. For example, if you add your company's logo to the form background of the toolkit's forms, users see your logo on the form during the application's installation because the wizard uses the toolkit's forms in the final setup routine that it creates and compiles.

Uninstalling the Application

The setup wizard not only generates the installable setup routine, but also an application uninstaller that lets users uninstall all the application's files at any time. The Application Setup Wizard hooks to the system Control Panel's Add/Remove Programs icon. Therefore, if users want to remove the application from the system, they only have to follow these steps:

  1. From the Start menu, choose Settings and then Control Panel.
  2. Double-click the Add/Remove Programs icon.
  3. Select the application from the list of installed applications. After getting verification that the user want to remove the application, the uninstall routine takes over, and removes the program and all its related files from the user's computer.

The Application Setup Wizard stores the uninstall information in the same directory as the application. The file that contains the removal instructions is named ST5UNST.LOG and holds the necessary details for the Add/Remove Programs system utility to do its job. Not all files should be removed, especially system files that might be shared by other programs. Before removing such potentially needed files (such as ActiveX controls), the removal utility displays Figure 37.12's warning dialog box that lets users decide how to remove such files.

FIG. 37.12

Users can decide whether to remove system files.

Summary

This lesson described the considerations necessary to install your application. Visual Basic's Application Setup Wizard does most of the work for you. When you answer a few of the wizard's questions, the wizard builds a complete installation routine that installs your application onto the users' machines.

The Application Setup Wizard is smart and lets you specify dependency information, such as ActiveX controls, that should install with your application's project files. Therefore, after you test, debug, and compile your application, you're ready to generate the installation routine. The Application Setup Wizard generates the installation onto floppy disks or hard disks, and you can install the application onto computers or even onto the Internet from Internet Explorer-based Web pages.

Your application stays on a user's computer until that user wants to remove it. To remove the application, users only have to select the Add/Remove Programs icon from the Control Panel and then select the application.

No questions or exercises exist for this lesson due to the general nature of the material.


© 1997, QUE Corporation, an imprint of Macmillan Publishing USA, a Simon and Schuster Company.