Download presentation
Presentation is loading. Please wait.
1
Visual Basic Debugging Tools Appendix D 6/27/20151Dr. Monther Aldwairi
2
Outline Debugging strategies Error Types – Compile, Run-Time and Logical errors VB Debugger – Breakpoints, watches and stepping through Error Trapping Common Errors 6/27/20152Dr. Monther Aldwairi
3
Debugging Errors in a program are called bugs The process of finding and correcting them is called debugging Debugging aims at eliminating or reducing the number of bugs in a program, thus making it behave as expected. 6/27/2015Dr. Monther Aldwairi3
4
Debugging strategies Tracing – Putting print statement in the code to verify flow and variable values during execution – Remove print statements after the error is detected Logfile – Text file to which a debugging trace is written – Debuggers read the log file (GDB for example) Error Trapping and Handling – Used to trap fatal errors 6/27/20154Dr. Monther Aldwairi
5
Preferable Debug Method Use a debugger! Allows you to pause during execution in order to view or alter variables 1.Setting breakpoints (to suspend program execution) 2.Defining watch values (to see current value of variables 3.Stepping into a program (executing one instruction at a time) 6/27/20155Dr. Monther Aldwairi
6
Error Types Compiler Errors – Syntactic, or compilation, errors occur when VB commands are written improperly. Run-time errors – An application attempts to perform an action that the system cannot execute Logical errors – Caused by faulty program logic. 6/27/20156Dr. Monther Aldwairi
7
Compiler Errors Visual Basic compiler errors occur when the compiler encounters problems in the code. A pop up windows is displayed 6/27/20157Dr. Monther Aldwairi
8
Run-time Errors Visual Basic run-time errors occur when an application attempts to perform an action that the system cannot execute. 6/27/20158Dr. Monther Aldwairi
9
Logical Errors The program compiles and runs fine The program does not give the expected output General debugging strategy: 1.Place breakpoint near (preferably, slightly ahead) of suspected error source. 2.Execute program in normal fashion, until breakpoint is encountered. 3.Define one or more watch values and step through the program, one instruction at a time. 4.Follow watch values to identify location, and possibly, source, of error. 6/27/20159Dr. Monther Aldwairi
10
Program Modes Design – Place controls on the form, set properties and write code Run (F5 or Start) Break – Invoked automatically when run-time errors are encountered – By clicking the break button or Ctrl-Break 6/27/201510Dr. Monther Aldwairi
11
Debugging Status Indicators 6/27/201511Dr. Monther Aldwairi Indicator Name SymbolDescription BreakpointSuspends program execution Current Statement Represents the next line to be executed. You can drag the current statement indicator to another line to either skip or re-execute code
12
Debug Menu 6/27/2015Dr. Monther Aldwairi12
13
Breakpoints Select statement, or click anywhere within statement, and set breakpoint: 1.Select Toggle Breakpoint from the Debug menu, or 2.Click on the Toggle Breakpoint button within the Debug toolbar, or 3.Press function key F9. A dark red point to the left of a statement indicates the existence of a breakpoint. The break in the program occurs just before the selected statement is executed. 6/27/201513Dr. Monther Aldwairi
14
Breakpoints To remove breakpoint use one of the three possibilities listed earlier to set a breakpoint. – To remove all break points select Clear All Breakpoints from the Debug menu, or use Ctrl- Shift-F9 Temporary breakpoint: click within a statement, select Run to Cursor from the Debug menu, or use Ctrl-F8. 6/27/2015Dr. Monther Aldwairi14
15
Defining watch values Watch values are the current values of variables or expressions There are two types of watch values: 1.Ordinary watch values: remain active as you step through the program 2.Break watches: The cause a break when True or when the values changes 6/27/201515Dr. Monther Aldwairi
16
To define watch values 1.Select Add Watch, from the Debug menu, and enter information in the Add Watch dialog box. 2.Right-click on the Watches window, select Add Watch. 3.Highlight an expression in the Code Editor window, and select Add Watch, from the Debug menu. 4.Highlight an expression in the Code Editor window. Then, right-click and select Add Watch. 5.Shift+F9 for quick watches 6/27/201516Dr. Monther Aldwairi
17
Adding Watches 6/27/2015Dr. Monther Aldwairi17
18
Stepping through a program Three different types of stepping: 1.Step Into results in line-by-line stepping of current procedure and subordinated procedures. 2.Step Over results in line-by-line stepping of current procedure, bypassing subordinated procedures. 3.Step Out results in execution of all remaining statements within the current procedure, and then pauses at the first statement following the procedure access in the parent routine. Note procedures will be discussed later in CH4 6/27/201518Dr. Monther Aldwairi
19
Stepping through a program To carry out line-by-line stepping do one of the following: 1.Select Step Into (or Step Over, Step Out) from the Debug menu 2.Press F8 to Step Into, Shift+F8 to Step Over, Ctrl+Shift+F8 to Step Out 3.Click on the Step Into button (or Step Over or Step Out button) on the Debug toolbar 6/27/2015Dr. Monther Aldwairi19
20
Error Trapping We will teach you later in Chapter 8 how to trap and handle fatal errors 6/27/201520Dr. Monther Aldwairi
21
Common Error Types #Error Type# 6Overflow58File already exists 7Out of memory61Disk full 9Subscript out of range62Input past end of file 11Division by zero71Disk not ready 13Type mismatch380 Invalid property value 52Bad file name or number382'Item' property cannot be set at run time 52File not found423Property or method not found 55File already open450Wrong number of arguments 6/27/201521Dr. Monther Aldwairi
22
Compile Errors Examples 6/27/201522Dr. Monther Aldwairi
23
Run Time Errors 6/27/201523Dr. Monther Aldwairi
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.