Walkthrough: Debugging at Design Time
This topic applies to:
Edition |
Visual Basic |
C# |
C++ |
Web Developer |
---|---|---|---|---|
Express |
||||
Standard |
||||
Pro and Team |
Table legend:
Applies |
|
Does not apply |
|
Command or commands hidden by default. |
You can use the Visual Studio Immediate window to execute a function or subroutine while your application is not running. If the function or subroutine contains a breakpoint, Visual Studio will break execution at the appropriate point. You can then use the debugger windows to examine your program state. This feature is called debugging at design time.
The following procedure shows how you can use this feature.
To hit breakpoints from the Immediate window
Paste the following code into a Visual Basic console application:
Module Module1 Sub Main() MySub() End Sub Function MyFunction() As Decimal Static i As Integer i = i + 1 Dim s As String s = "Add Breakpoint here" Return 4 End Function Sub MySub() MyFunction() End Sub End Module
Set a breakpoint on the line that reads, s="Add BreakPoint Here".
Type the following in the Immediate window: ?MyFunction<enter>
Verify that the breakpoint was hit, and that the call stack is accurate.
On the Debug menu, click Continue, and verify that you are still in design mode.
Type the following in the Immediate window: ?MyFunction<enter>
Type the following in the Immediate window: ?MySub<enter>
Verify that you hit the breakpoint, and examine the value of static variable i in the Locals window. It should have the value of 3.
Verify that the call stack is accurate.
On the Debug menu, click Continue, and verify that you are still in design mode.