DEBUGGING

Visual Basic provides a rich set of tools for debugging an application. Using the development environment, you can stop the program at different lines of code and examine variables, change variable values, look at the call stack, and call routines to exercise different pieces of the application. You can step through the program, executing the code one statement at a time to see what it is doing. You can even make some modifications to the source code and let the program continue running.

Chapter 6, “Debugging,” describes tools that the development environment provides to help you debug an application. These include tools for stepping through the code, breakpoints, and windows such as the Immediate, Locals, and Call Stack windows. See Chapter 6 for details.

In addition to setting breakpoints in the code, you can use the Stop statement to pause execution at a particular line. This can be particularly useful for detecting unexpected values during testing. For example, the following statement stops execution if the variable m_NumEmployees is less than 1 or greater than 100:

If (m_NumEmployees < 1) Or (m_NumEmployees > 100) Then Stop

Get Visual Basic 2012 Programmer's Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.