1 / 23

Visual Basic Debugging Tools

Visual Basic Debugging Tools. Appendix D. Outline. Debugging strategies Error Types Compile, Run-Time and Logical errors VB Debugger Breakpoints, watches and stepping through Error Trapping Common Errors. Debugging. Errors in a program are called bugs

oleg-beck
Download Presentation

Visual Basic Debugging Tools

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Visual Basic Debugging Tools Appendix D Dr. 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 Dr. 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. Dr. Monther Aldwairi

  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 Dr. Monther Aldwairi

  5. Preferable Debug Method • Use a debugger! • Allows you to pause during execution in order to view or alter variables • Setting breakpoints (to suspend program execution) • Defining watch values (to see current value of variables • Stepping into a program (executing one instruction at a time) Dr. 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. Dr. Monther Aldwairi

  7. Compiler Errors • Visual Basic compiler errors occur when the compiler encounters problems in the code. • A pop up windows is displayed Dr. 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. Dr. Monther Aldwairi

  9. Logical Errors • The program compiles and runs fine • The program does not give the expected output • General debugging strategy: • Place breakpoint near (preferably, slightly ahead) of suspected error source. • Execute program in normal fashion, until breakpoint is encountered. • Define one or more watch values and step through the program, one instruction at a time. • Follow watch values to identify location, and possibly, source, of error. Dr. 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 Dr. Monther Aldwairi

  11. Debugging Status Indicators Dr. Monther Aldwairi

  12. Debug Menu Dr. Monther Aldwairi

  13. Breakpoints • Select statement, or click anywhere within statement, and set breakpoint: • Select Toggle Breakpoint from the Debug menu, or • Click on the Toggle Breakpoint button within the Debug toolbar, or • 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.  Dr. 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. Dr. Monther Aldwairi

  15. Defining watch values • Watch values are the current values of variables or expressions • There are two types of watch values: • Ordinary watch values: remain active as you step through the program • Break watches: The cause a break when True or when the values changes Dr. Monther Aldwairi

  16.    To define watch values • Select Add Watch, from the Debug menu, and enter information in the Add Watch dialog box. • Right-click on the Watches window, select Add Watch. • Highlight an expression in the Code Editor window, and select Add Watch, from the Debug menu. • Highlight an expression in the Code Editor window. Then, right-click and select Add Watch. • Shift+F9 for quick watches Dr. Monther Aldwairi

  17. Adding Watches Dr. Monther Aldwairi

  18. Stepping through a program • Three different types of stepping: • Step Into results in line-by-line stepping of current procedure and subordinated procedures. • Step Over results in line-by-line stepping of current procedure, bypassing subordinated procedures. • 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 Dr. Monther Aldwairi

  19. Stepping through a program • To carry out line-by-line stepping do one of the following: • Select Step Into(or Step Over, Step Out) from the Debug menu • Press F8 to Step Into, Shift+F8 to Step Over, Ctrl+Shift+F8 to Step Out • Click on the Step Into button (or Step Over or Step Out button) on the Debug toolbar Dr. Monther Aldwairi

  20. Error Trapping • We will teach you later in Chapter 8 how to trap and handle fatal errors Dr. Monther Aldwairi

  21. Common Error Types Dr. Monther Aldwairi

  22. Compile Errors Examples Dr. Monther Aldwairi

  23. Run Time Errors Dr. Monther Aldwairi

More Related