How to Make VB Debugger Go Into Code
Visual Basic (VB), the programming language and development environment by Microsoft, has several tools to help developers write error-free programs. One of those tools is a debugger, which is a mode for catching errors in the currently executing program. The debugger can step into source code, which allows the programmer to run statements interactively. To make the debugger step into code, programmers can set breakpoints or purposely create certain types of program errors. Doing either of these allows the programmer to locate problems with a program or inspect the runtime values of the program's variables.
Instructions
-
-
1
Open the Visual Basic environment and click the opening screen's "New Project" link to begin creating a blank program that you'll customize. Double-click the "Windows Form application" item on the screen that follows.
-
2
Right-click the item "Form1.VB" in the "Solution Explorer" pane at screen right, then click the "View designer" option. VB will display the window for placing controls on the user input form. You'll make the debugger pause execution of the program that processes this form.
-
-
3
Click the toolbar's "Tool box" icon to display the list of controls that can be dragged onto the form. Drag a text box control from the list onto the form, then drag a button from the list to a position below the text box.
-
4
Double-click the button to enter the window for writing the source code to process the form's input.
-
5
Paste the source code at the end of this instruction above the "End sub" statement of the subroutine "Button1_Click." This program reads the text the user enters into the text box you placed in Step 3. It then adds additional text and prints out a message.
Dim s
s = TextBox1.Text
s = "Hello " & s
MsgBox(s)
-
6
Click the "Debug" menu's "Step into" item to begin executing the program statement by statement. VB will display the form you designed in Step 3.
-
7
Type your name in the text box, then press the form's button. The debugger will pause program execution and display a yellow highlighted statement, "Button1_Click." The highlight indicates that this statement is the next that VB will run once you tell it to do so.
-
8
Press "F8" repeatedly to execute each statement of your program. Before the yellow highlight reaches the last statement ("End Sub"), click the yellow arrow in the left margin, then drag it to any previous statement in the source code. This action tells the debugger to make the statement to which you dragged the arrow the next to execute.
-
9
End the program by clicking the "Debug" menu's "Stop debugging" item.
-
1
References
Resources
- Photo Credit binary world image by Attila Toro from Fotolia.com