Using revision numbersThe 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.
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 propertiesThe 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.
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.
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 codeA 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
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.
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.
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 projectFor 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.
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.
Save installation files to hard driveDon'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.
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.
Working with CAB filesThe 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.
FIGURE 20.9 This dialog shows a complete list of the files required to make this application run on another computer.
FIGURE 20.10 Enter the title of your application in this dialog.
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.
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.
FIGURE 20.15 The last step in the wizard enables you to give your script a name for later use.
© Copyright, Macmillan Computer Publishing. All rights reserved.