1 / 8

Coding and Debugging

Coding and Debugging. Requirements and Specification. Recall the four steps of problem solving: Orient, Plan, Execute, Test Before you start the implementation phase of your project (the Execute step), you should complete the prior two steps

mauve
Télécharger la présentation

Coding and Debugging

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. Coding and Debugging

  2. Requirements and Specification • Recall the four steps of problem solving: Orient, Plan, Execute, Test • Before you start the implementation phase of your project (the Execute step), you should complete the prior two steps • You will do this by creating a requirements and specification document; a sample is provided

  3. Bugs • Errors in a program are called “bugs” • Don’t feel that your program should work right the first time. Almost every program starts out with bugs, even when written by experts • The process of finding and correcting the errors is called “debugging”

  4. Three Types of Errors 1 • Syntax error: (VBA calls these compiler errors) This is a mistake in the form of your program. The VBA editor will catch these and turn the offending line red. It will also suggest ways to fix it. Usually the suggestions are right but they may not be. • Run-time error: This causes your program to freeze up or crash while running. A well-written program shouldn’t do this, even if the user does something wrong. We’ll learn some methods to avoid these later.

  5. Three Types of Errors (2) • Logic errors: These are the most insidious errors, because it looks like the program is running correctly. Remember that the computer has no common sense and just does what you tell it to, no matter how silly. You use tests to see if you have logic errors, which is why the tests are of critical importance.

  6. Stepping Through • VBA has a great feature to let you see your program in action • If you go to the code page, choose a subroutine to run (by clicking the title) and choose Step Into from the Debug menu (or use the F8 key on Windows, command-shift-I on the Mac; that’s the letter “i”), the computer will execute your program line by line • The next line to be executed is highlighted in yellow • Keep pressing F8 or command-shift-I to advance through the code • After a line has executed, you can hover the mouse over the variable names and see their current values • If you see a value you didn’t expect, you have found a bug • Go to the Run menu and click Reset to change your code and try again

  7. Compiling vs Interpreting • When you step through your code, VBA looks at it and executes it line by line. This is called interpreting the code. • Normally when you run your program, VBA compiles it, meaning it is translated into a form that runs quickly on your machine, similar to an exe file on Windows

  8. Be Persistent • Programming requires you to pay attention to detail • Your program won’t run till every last syntax error is fixed • Once it runs, you need to do your tests and track down any bugs • The TA can help you if you get stuck. Or use the discussion groups on D2L

More Related