BugAssert and other debug procedures expect a constant named afDebug to indicate not only whether debugging is on but also where to send debug output. You can set the constant in several ways.
The easiest way to set afDebug is to ignore it, which has the effect of setting it to 0 (False). Your code will work, but your assertions won’t. This is a good setting for your release builds.
You can also set the constant in the DEBUG.BAS source module. You might think that it would be handy to set the afDebug constant in each source file so that you could debug some modules and not others. Unfortunately, that doesn’t work. Constants defined in source modules are module-level variables. BugAssert and other routines that test the afDebug constant are located in DEBUG.BAS. They don’t know or care about constants defined in other modules. Since you’ll use the DEBUG.BAS module in various projects, you don’t want the value of the afDebug constant to change every time you modify it in the source file. Instead, you want a projectwide way of setting the constant.
You can set project constants on the Make tab of the Project Properties dialog box (as shown in Figure 1-3), or you can set them on the VB5.EXE command line. If you spend all of your time working on one project, the command line method might work for you. I switch projects constantly, so I find the Project Properties dialog box more convenient. This puts the constant entry into the project, as you can see by examining the VBP file.
Figure 1-3. The Make tab of the Project Properties dialog box.
The Project Properties dialog box and the command line don’t know Basic. You can’t enter True or False, constants that are defined in the source file, hexadecimal numbers, or Basic operators. If you need to combine bit constants, you can’t use an expression such as afDebugWin And afLogFile. Instead, you have to
figure out that this means &H1 And &H4, calculate, convert to decimal, and enter afDebug = 5 in the Conditional Compilation Arguments field.
Because my standard configuration is to send debugging output to the Immediate window and create a log file (afDebug = 5), I make it a standard setting in my default project and in my templates.
NOTE Visual Basic now provides two ways to customize your startup projects. You can define a default startup project by creating a project with all your favorite settings and naming it AUTOLOAD.VBP. You can also define templates for common project types by creating skeleton projects and placing them in the Visual Basic template directory. Both techniques are handy, but the documentation for templates is thin and the documentation for AUTOLOAD.VBP is nonexistent. You’ll have to experiment.