250 likes | 820 Views
Debugging Code in Visual Basic. Overview. Types of Errors Debugging Terms Debugging Code in Visual Basic Using the Call Stack Using Watch Variables to Monitor Program Execution Using the Locals Window. Types of Errors. Programming errors generally fall into 3 areas: Syntax Run-Time
E N D
Overview • Types of Errors • Debugging Terms • Debugging Code in Visual Basic • Using the Call Stack • Using Watch Variables to Monitor Program Execution • Using the Locals Window
Types of Errors Programming errors generally fall into 3 areas: • Syntax • Run-Time • Logic
Debugging Terms • Break Mode vs. Run Mode • Watch Expressions • Watch Point Variables • Debug Windows
Run Mode vs. Break Mode • Run mode is like “Run”. The application is executing. F5 is the shortcut to execute your code. • Break Mode is like “Pause”. Visual Basic will enter Break Mode when: • The program hits a manual break point (F9 is the toggle key) • The program hits a Stop statement • A watch is triggered • Ctrl-Break (especially nice for endless loops!) • A run-time error occurs and the Debug option is chosen.
What can you do in Break Mode? What can’t you do? When in Break mode you can: • Modify the application code • Check variables • Change values • Change the program flow • Execute Visual Basic statements, functions
Setting BreakPoint • Manual toggle F9 or • Put in a stop • Using a Debug.Assert Statement You can conditionally enter Break mode using the Debug.Assert method. This method uses a Boolean expression to determine where or not to enter Break mode:Debug.Assert BooleanExpression Note: Asserts only work within the development environment.
Watch Expressions What’s a Watch?Hint: It’s not a Timex. A watch allows you to : • Monitor the behavior of a variable or expression as the program executes. • Under certain conditions a Watch can kick you into Break mode, for example when a particular value changes or becomes True. Watch Expressions are viewed in the Watch Window.
Using the Immediate Window What’s in the Variable? • ? Variable This will print out the value contained by the variable. Example ? Me.Name I don’t want that value, I want THAT value • Variable = Value This will set the variable to be a specific value. Example: strHolder = “Kilroy was Here” intHolder = 100
Local Window • Local Window is everything on steroids
Call Stack (Ctrl + L) • How did I get Here?
Debugging Toolbar “Window” Buttons Locals Window Immediate Window Watch Window Add Quick watch Call Stack Window “Flow” Buttons Breakpoint toggle Step Into Step Over Step Out “Action” Buttons Run Pause Stop
Summary • Types of Errors • Debugging Terms • Debugging Windows • Debugging Code in Visual Basic • Using the Call Tree • Using Watch Variables to Monitor Program Execution
Useful Web Sites • Beginning VB http://groups.msn.com/NTPCUGDevToolsSIG • Advanced VBhttp://rsj-services.com/ntpcug/ • Developer Issues http://members.tripod.com/appdevissues/ • Accesshttp://members.tripod.com/ntaccess/ • Microsoft Developer SIGShttp://ntmsdevsigs.homestead.com/ • North Texas PC Users Grouphttp://www.ntpcug.org/