devxlogo

Include Code for Debugging

Include Code for Debugging

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.

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist