Visual Basic Concepts

Using Compile on Demand

Compile on Demand and Background Compile are related features that allow your application to run faster in the development environment. It's possible that using these features may hide compile errors in your code until you make an exe for your entire project. Both features are turned on by default, and they can be turned on or off on the General tab of the Options dialog box available from the Tools menu.

Compile on Demand allows your application, in the development environment, to compile code only as needed. When Compile on Demand is on and you choose Start from the Run menu (or press the F5 key), only the code necessary to start the application is compiled. Then, as you exercise more of your application's capabilities in the development environment, more code is compiled as needed.

Background Compile allows Visual Basic at run time in the development environment to continue compiling code if no other actions are occurring.

With these features turned on, some code may not be compiled when a project is run in the development environment. Then, when you choose to Make EXE file (or turn off Compile on Demand), you may see new and unexpected errors as that code is newly compiled.

There are three techniques you can use at development milestones, or any other time, to flush out any errors hidden by using Compile on Demand.

  • Turn Compile on Demand off and then run the application. This forces Visual Basic to check the entire application for compile errors.

  • Make an executable with your project. This will also force Visual Basic to check the entire application for compile errors.

  • Choose Start With Full Compile from the Run menu.