Microsoft
Visual Studio .NET and Microsoft Visual Studio 2005 provide several ways to help you debug .NET Framework applications. This step-by-step article explains how to use breakpoints to debug a section of code that is written in Microsoft Visual Basic .NET or in Microsoft Visual Basic 2005.
This article assumes that you are familiar with Visual Basic .NET syntax or Visual Basic 2005 syntax.
Start Visual Studio .NET or Visual Studio 2005, and create a new Visual Basic Console Application project named Debug.
Modify the code in Module1.vb as follows:
Module Module1
Sub Main()
Dim MyTime As String = TimeString
Dim MyGreeting As String
' Create a greeting.
If CInt(TimeString.Substring(0, 2)) < 12 Then
MyGreeting = Reverse("Good Morning")
Else
MyGreeting = Reverse("Good Afternoon")
End If
' Display reversed greeting.
Console.WriteLine(MyGreeting)
End Sub
Function Reverse(ByVal inStr As String) As String
' Reverses the characters contained in a string.
Dim MyInt As Integer
Dim MyStr As String
For MyInt = (inStr.Length - 1) To 0 Step -1
MyStr = MyStr & inStr.Substring(MyInt, 1)
Next
Return MyStr
End Function
End Module
In the Breakpoints window, click New to create a new breakpoint.
On the Function tab, type Reverse for Function. Type 1 for Line, type 1 for Character, and then set Language to Basic.
Click Condition and make sure that the Condition check box is selected. Type instr.length > 0 for Condition, make sure that the is true option is selected, and then click OK.
In the New Breakpoint dialog box, click OK.
On the Debug menu, click Start.
The program stops at the IF statement in the Main method. To continue program execution, click Continue on the Debug menu.
The program stops again at the Reverse function. Continue to run the program.
Start the program in debug mode. When the program reaches the first breakpoint, on the Debug menu, click Step Over. This steps over the breakpoint and onto the next statement.
If you are running this program in the morning, you see the following statement:
MyGreeting = Reverse("Good Morning")
If you are running the program in the afternoon, you see the Else statement. Press F10 again to step onto the following statement:
MyGreeting = Reverse("Good Afternoon")
On the Debug menu, click Step Into. This steps into the Reverse function.
Continue to click Step Over on the Debug menu until you reach the following statement for the second time:
MyStr = MyStr & inStr.Substring(MyInt, 1)
Remove the current breakpoint by clicking in the left margin.
On the Debug menu, click Step Out. This steps you out of the Reverse function.
You may create breakpoints only on executable lines of code. For example, breakpoints are not acceptable on comments or on variable declarations without default values.
You may assign function breakpoints on only the first line of the function declaration.
Microsoft does not support data breakpoints in Visual Basic .NET.