Debugging & Handling Exceptions in Visual Basic
Visual Studio detects syntax errors and underlines then in blue
Warnings are underlines in green
Debugging
To debug you must be in debugging mode
Press F5 or the play button to run your project
Visual Studio Tools for debugging
Error Window
When you have an error it will show up in the error window
Double-click on the error and it takes you to that part of the code
Open the error windows by selecting View Error List or View Other Windows and then errorList
Breakpoint
Place this on a line of code to pause execution at that point
Immediate Window
Lets you type commands and see potential results
Your application must be paused to view the value of the variables
Set up Breakpoints
Create a breakpoint by clicking in the gray bar to the left of your code.
Click next to the line of code you want to pause at
A red dot appears in the gray bar indicating a breakpoint
To remove the breakpoint cimply click it again
When you click play, the program stops at this line
F5 continues execution
Breakpoint Window
Control + ALT+B opens the breakpoint window
Or Debug menu and click Windows and then Breakpoints
Use this window to keep track of all your breakpoints
Immediate Window
Use the Debug.print command to view values
(?) Question mark is a shortcut for Debug.print
Project must be in a paused state
Example:
?VariableName
- Start as new project
- Add this code
Dim num1 As Integer = 0
- Add a button and add this code
num1 += 1
Add two breakpoints next to the code
- Open the immediate window
- Type ?num1
- Click on F10
- Click the button
- Click F10 and type ?num1
- Until the value turns to 1
Notice how it is stepping through your code