Compiling an Application

Visual Basic makes compiling your application simple. The compiled file is a final executable file with the .EXE filename extension. 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.

note

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 users couldn't even run the source code for your program, because they don't have Visual Basic to load and run the program. Therefore, a compiled file is necessary so that all can use your application.

Your compiled application runs much faster than the application running within Visual Basic'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 you've debugged the application as much as feasible possible. You can't debug compiled applications with the Visual Basic 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 File|Make. Visual Basic displays the Make Project dialog box (see Figure 21.9). Select the folder where you want to store the compiled application. (Visual Basic uses the project name as the default executable name.)

Figure 21.9

Compiling the application from the Make Project dialog box.

Before clicking OK to start the compilation, click the Options button to display the Project Properties dialog box (see Figure 21.10). (You also can access this dialog box by choosing Properties from the Project menu.) The dialog box lets 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.

Figure 21.10

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

The Icon entry designates the application's icon that appears on the Windows Start menu and on a taskbar button. Generally, you'll leave the primary form name in the Icon field. The form's Properties window also 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 21.11). To optimize the compiled project to make it run as quickly as possible, select the Compile to Native Code option. (If you compile to p-code, or pseudocode, the application requires that your users keep a runtime Visual Basic[nd]based DLL file in their Systems folder. Native code runs faster and requires fewer files.)

Figure 21.11

The Compile page holds the project's compilation options.

note

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 Project Properties 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 after locating the .EXE file. The form's icon that you selected appears in the taskbar when you run the program.

Top Home