VB supports conditional compilation, just like Visual C++. However, Visual C++ has a predefined constant named _DEBUG that makes it easy to include code only while debugging, as in this code:
#ifdef _DEBUG MessageBox(NULL,"Begin Procedure", _ "Debug Message",MB_OK);#endif
In VB, you can do the same thing, but you need to declare the variable in the Conditional Compilation Arguments fields in the Make tab of the Project properties dialog, then remember to remove it before shipping the executable. Using the Debug.Assert command is an easier way to have statements executed only while debugging and not when running a compiled program.
For example, this line displays a message box only when running the program in the design environment and not in a compiled program:
Debug.Assert MsgBox("Begin Form_Load")
This happens because Debug.Assert works only in the design environment. To evaluate the assertion, VB executes the statement. However, when you compile the program, the compiler removes this line from the executable.