me 142 engineering computation i

18
ME 142 Engineering Computation I Debugging Techniques

Upload: josephine-kirkland

Post on 31-Dec-2015

44 views

Category:

Documents


0 download

DESCRIPTION

ME 142 Engineering Computation I. Debugging Techniques. Key Concepts. Types of Program Errors Debugging Tools & Techniques Testing. Types of Programming Errors. Syntax Errors Run-Time Errors Logic Errors. Syntax Errors. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: ME 142 Engineering Computation I

ME 142Engineering Computation I

Debugging Techniques

Page 2: ME 142 Engineering Computation I

Key Concepts

Types of Program Errors Debugging Tools & Techniques Testing

Page 3: ME 142 Engineering Computation I

Types of Programming Errors

Syntax Errors Run-Time Errors Logic Errors

Page 4: ME 142 Engineering Computation I

Syntax Errors

Syntax errors occur when the rules of the programming language are violated.

Examples: Misspelling a keyword or function name Misplacement or omission of a parenthesis or

quote mark Omission of necessary keywords in a command.

Page 5: ME 142 Engineering Computation I

Run-Time Errors

Runtime errors are those errors that occur when a program free of syntax errors, runs and generates an error.

Examples: Attempting an invalid operation such as division

by zero Providing the wrong data type to a function.

Page 6: ME 142 Engineering Computation I

Logic Errors

Logic errors are due to incorrect program logic.

The program may run without errors The results it returns are inaccurate. Often the most difficult to locate

Page 7: ME 142 Engineering Computation I

Debugging Tools & Techniques

MsgBox Function Debug.Print Statement Debug Mode

Page 8: ME 142 Engineering Computation I

MsgBox Statement

Place MsgBox statement in your code as desired

Causes the value of the variables to be immediately displayed in a dialog box and pauses execution of program

Example:

MsgBox (“A = “ & A)

Page 9: ME 142 Engineering Computation I

Debug.Print Statement

Place Debug.Print statement in your code as you would MsgBox function

Causes the value of the variables to be printed in the Immediate window

Example:

Debug.Print A,B,C

Page 10: ME 142 Engineering Computation I

Debug.Print Statement

Page 11: ME 142 Engineering Computation I

Debug Mode

Allows you step through your program and examine the value of variables at specific points

May step through line-by-line or set specific breakpoints

Page 12: ME 142 Engineering Computation I

Debug Mode

When a run-time error occurs may enter Debug Mode by selecting button on dialog box that appears:

Page 13: ME 142 Engineering Computation I

Debug Mode

Once in Debug Mode may mouse-over a variable to find its current value:

Page 14: ME 142 Engineering Computation I

Debug Mode

May also hit the F8 key to single step through the program

Each time the F8 key is hit, one line of code is executed:

Page 15: ME 142 Engineering Computation I

Debug Mode

May also set a breakpoint by clicking in the gray column on the left side of the line of code you want to program to pause on

Click on run (from menu above) to cause the program to resume

Page 16: ME 142 Engineering Computation I

Debug Mode

Another powerful feature to use in conjunction with the previous techniques is the Locals Window

It displays the current value of all local variables in your program

Page 17: ME 142 Engineering Computation I

Testing

Deadly Misconception of Beginning Programmers: If a program runs without errors, the results must

be correct Very important that before you use your

program to make engineering decisions (or turn it in to get a grade in class) that you perform a series of test to make certain that the output is correct.

Page 18: ME 142 Engineering Computation I

Testing Suggestions

Compare your results to that of a simple, known problem by using a calculator or Excel

Test a typical range of inputs Test unusual but valid data Test extreme values