Using Visual Basic 6

Previous chapterNext chapterContents


- 20 -
Deploying Your Visual Basic Applications


Working with Version Information


Using revision numbers

The revision number is also known as the build number because it signifies how many times the application has been compiled by its creator. This is often helpful in technical support issues because the revision number is how bugs can be tracked.


One of the first professional touches you can add to your application is to provide commonly requested application information. This information includes the company name, the version number, the revision (or build) number, and other similar information. Visual Basic enables you to store all this information through the use of the App object, a predefined object in Visual Basic that doesn't need to be specifically created by your application.

Most properties of the App object are used to provide general information about your application. Table 20.1 shows the most commonly used properties.

TABLE 20.1  Commonly Used App Object Properties

Property Description
Comments Returns a string containing comments about the application. Read only at runtime.
CompanyName Returns company or creator. Read only at runtime.
EXEName Returns filename of .EXE without extension. Read only.
FileDescription String that briefly describes the application's purpose. Read only at runtime.
HelpFile Specifies the help file associated with the application. Read and write at runtime.
LegalCopyright Returns copyright notification string. Use the Character Map program to add special symbols in this box. Read only at runtime.
LegalTrademarks Returns trademark information, if necessary. Use the Character Map program to add special symbols in this box. Read only at runtime.
Major Returns major version number (for example, the 4 in 4.3). Read only at runtime.
Minor Returns minor version number (for example, the 3 in 4.3). Read only at runtime.
Path Returns the directory from which the application started. Read only at runtime.
PrevInstance Returns a value if an instance of the application is running. Read only at runtime.
Product Name Returns the assigned product name of the application. Read only at runtime.
Revision Returns the revision number of the application. Read only at runtime.

You can use these properties to communicate important information about your application to those who will be using it. These properties are set in the Project Properties dialog (see Figure 20.1).

You can read the values of these properties at runtime within your VB code (see Listing 20.1). You can also set the value for the version information properties of the App object by right-clicking the compiled EXE file and selecting Properties from the pop-up menu (see Figure 20.2).


Read-only App properties

The values of the App object's version information properties are embedded within the binary format of your Visual Basic executable. They can't be changed at runtime.


LISTING 20.1  Reading an App Object's Properties in Code

01 Private Sub cmdCopyright_Click()
02 lblMain.Caption = App.LegalCopyright
03 End Sub
04
05 Private Sub cmdPath_Click()
06 lblMain.Caption = App.Path
07 End Sub
08
09 Private Sub cmdProductName_Click()
10 lblMain.Caption = App.ProductName
11 End Sub
12
13 Private Sub cmdVersionNum_Click()
14 Dim strVerNum
15
16 strVerNum = CStr(App.Major) & "." _
& CStr(App.Minor) & "." _
& CStr(App.Revision)
17
18 lblMain.Caption = strVerNum
19 End Sub

FIGURE 20.1 To access the Project Properties dialog, choose ProjectName Properties from the Project menu.

FIGURE 20.2 Select the Version tab in Windows Explorer to see the version properties.

Working with the App object's properties is important because through these properties you and your users can manage multiple releases of your code. Also, using the version properties of the App object, such as LegalCopyright and LegalTrademark, is the way by which users can verify that the program you made is really yours, thus avoiding potential incidents of piracy.

Compiling Your Project

After you set the values for the properties of your project's App object, you can compile your code. Up to this point in your programming activity, your project has been a collection of text and graphic files, which you've built with the Visual Basic IDE. Now it's time to transform these files into an executable file that will run independently of the IDE. This process is called compiling your code or making an executable.

Visual Basic 6.0 supports two formats into which you can compile your code: P-code or native code. When you compile your code into P-code, the resulting executable file runs as interpreted code, just as it did in previous versions of Visual Basic. (P-code isn't the same thing as pseudocode.) Interpreted code is read by a runtime engine that determines the instructions to run. It's like giving someone an instruction sheet to build a product instead of giving them the product directly. The person receiving the instructions has to put all the pieces together correctly to create the end product.


P-code versus native code

A native code executable file tends to be bigger in size than its P-code cousin. Thus, if you want to deploy the smallest possible executable file, you should use P-code. However, if you want the fastest code possible, you should distribute your application in Native code.


If you compile the code as native code, the project files are transformed into more efficient binary code that uses your computer processor's full capabilities. This code tends to execute much faster. However, native code still requires the runtime DLLs--the only difference is that the DLLs are accessed and used differently by the EXE.

Compile your code into a standard EXE

1. Open the project that you want to compile.

2. Choose Make ProjectName.exe from the File menu. The Make Project dialog appears (see Figure 20.3).

FIGURE 20.3 Enter the name of the executable in this dialog. Click the Options button to change some of the App object's properties.

3. Rename the executable file in the File Name text box, if you want.

4. Click the Options button to open the Project Properties dialog. On the Compile page, choose between P-Code or Native Code compilation (see Figure 20.4).

5. Click OK in the Project Properties and Make Project dialogs to compile the code.

FIGURE 20.4 You can select from many options for native code compilation. Generally, the faster code option creates a larger file size for the executable.


The make process that you've just completed pertains to standard EXE projects. You can make many other types of projects with Visual Basic 6.0, including ActiveX controls and ActiveX DLLs. This chapter is focusing on making standalone executables, however; building ActiveX controls is covered in Chapter 27, "Creating Your Own ActiveX Controls with Visual Basic."

Completing this process produces an executable file that runs outside the Visual Basic IDE. However, your application isn't fully ready for deployment. To deploy the application, you need to run the Application Setup Wizard for the executable to be able to run on a system on which Visual Basic is not installed.

Using the Package and Deployment Wizard

Because Visual Basic applications can be created in many different forms and used on different platforms, including the Internet, the old Application Setup Wizard has been replaced by the Package and Deployment Wizard in Visual Basic 6. You can use this tool to create installation packages for any type of application you build in Visual Basic. This section concentrates on creating an installation package for a standalone application.

To begin, start the Package and Deployment Wizard (shown in Figure 20.5). It should be listed on the Visual Basic submenu of your Start menu because it's installed by default. If not, you might have to install the tool on your system.

If you have ever used a previous version of the Setup Wizard included with Visual Basic, this tool will amaze you. Microsoft finally listened to programmer complaints and included a respectable installation tool. It doesn't do everything, but it can handle most of the simple installations required for Visual Basic applications.

FIGURE 20.5 The Package and Deployment Wizard is new with Visual Basic 6.0. It replaces the Setup Wizard.

Create an installation package


Selecting a sample project

For these steps, you can use any Visual Basic project you have, or you can use a sample from Visual Basic. This section uses the ATM sample project included with VB.


1. Select the project file at the top of the dialog.

2. To build a self-extracting setup program, click the Package button.

3. If you haven't compiled your application, the wizard will ask to compile the application for you (see Figure 20.6). Click the Compile button to continue.

FIGURE 20.6 The wizard needs to bundle an EXE file with the setup program, so it automatically compiles the application for you from the VB project file.

4. After the wizard compiles your application, it will ask you what type of package you want to build (see Figure 20.7). Select Standard Setup Package and click the Next button.


Save installation files to hard drive

Don't tell the wizard to save your files to floppy or CD-ROM at this point in the process; the wizard needs to modify the files several times before completing the process. Store the files on your hard drive and create the CD when the process is all done.


5. Indicate where you want to place the installation files that the wizard will create. These files will eventually be copied to your distribution media, whether it be a disk or CD-ROM. Select a directory (see Figure 20.8) and click Next to continue.

FIGURE 20.7 Select the type of package you want to build with the wizard.

FIGURE 20.8 The wizard needs a temporary holding location for the files involved in the installation.

6. As mentioned earlier, Visual Basic applications consist of more files than just the executable. The next dialog (see Figure 20.9) lists the files that need to be installed with your executable. If you have other files (such as help files, as discussed in Chapter 24, "Adding Help to Your Programs") that should be installed, you can add them at this point. Because you don't have any other files in this case, click Next to continue.


Working with CAB files

The files that the wizard will produce are called CAB, or cabinet files. These files are a special type of archive file designed by Microsoft, much like a ZIP file. If you use the popular utility WinZIP, the 7.0 release will have support for viewing the contents of CAB files. CAB files are used by various tools, including Windows 98, for storing installation files.


7. The next step in the wizard deals with the size of the distribution media you want to use. If you plan to put your application on disks, the biggest file that the wizard can produce is the maximum size of the disk. Because you're not actually going to copy these files to floppy for this example, select the Single Cab option and click Next to continue.

FIGURE 20.9 This dialog shows a complete list of the files required to make this application run on another computer.

8. Next, specify the title of your application (see Figure 20.10). This title will be shown during installation. Enter an appropriate title and click Next to continue.

FIGURE 20.10 Enter the title of your application in this dialog.

9. For your application to be used, it needs to have an icon on the Start menu. The next step in the wizard (see Figure 20.11) is a unique way to specify the icon groups and icons to create. The default settings are to create a group with the application's name and then to create an icon to start the program.

Because the application has only a single icon, the standard is to create that icon under Programs. Click the ATM group and then click the Remove button. Next, click the New Item button, enter the name of the application, and click OK in the dialog that appears (see Figure 20.12). Click Next when you're finished adding groups and icons.

FIGURE 20.11 Pick the icons and groups you want created for your application.

FIGURE 20.12 Specify certain options about each icon you want to create.

10. The next dialog (see Figure 20.13) enables you to change the installation location of each file that's not required by the system. All system files are automatically installed in the \Windows\System directory; everything else is up to you. Because the specified directory is correct for this example, click Next.

11. Certain files, such as DLLs and OCXs, are considered shared files. If you were adding any of these files as part of your installation, they should be marked as shared so that when users uninstall your application, the shared files are verified before removal. The dialog shown in Figure 20.14 lets you mark any files as shared. Standalone executables like this one normally aren't shared, however, so click Next.

FIGURE 20.13 If you need to change the installation directory for files you've added, this dialog lets you do it.

FIGURE 20.14 Mark any shared files as such in this dialog.

12. Give your script a name (see Figure 20.15) and click the Finish button to build your installation package.

FIGURE 20.15 The last step in the wizard enables you to give your script a name for later use.

13. After the wizard finishes building the installation package, it generates a report with some important messages about what was accomplished. Read the report and then click Close on the report and the wizard.


Previous chapterNext chapterContents

© Copyright, Macmillan Computer Publishing. All rights reserved.