Lectures 17 - Assignment7Lectures

Lectures 17 - Assignment7Lectures - March 15, 2010 Click to...

Info iconThis preview shows pages 1–15. Sign up to view the full content.

View Full Document Right Arrow Icon
Click to edit Master subtitle style 3/17/10 March 15, 2010
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3/17/10 Debugging Review Give a man a fish and you feed him for a day. Teach a man to fish and you feed him for a lifetime. – Ancient Proverb Help a student to fix a bug, and he or she is set until the next bug. Teach that student to use the debugging tools, and maybe we can all get some sleep. – IOE 373 Proverb
Background image of page 2
3/17/10 Debugging Hint 1: Read the Error Message Not all error messages are easy to understand, but some are. I’m always amazed at the forum posts which say “I ran this code and got an error.” Um…What did the error say??? By now, you should know what “Object reference not set to an
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3/17/10 Debugging Hint 2: Don’t Hit the Stop Button! If you run your code and you get to a point where it stops on a line of code, read the message, and then do… Nothing! When VB stops on a line of code, it is in debugging mode. By stopping on that line of code, VB is giving you a big hint: THERE’S SOMETHING WRONG WITH THAT LINE OF CODE!
Background image of page 4
3/17/10 In this example, we have experienced the most common error: “Object reference not set to an instance of an object.” VB doesn’t tell us which reference is
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3/17/10 Don’t Stop That Program! This information is pretty easy to find —if we don’t stop the program. We are looking for a variable with a value of “Nothing”. We can use Quick Watch to find it. Recall that Quick Watch is available on the right-click menu; right click on the variable that you want to check, and select Quick Watch.
Background image of page 6
3/17/10 QuickWatch on s indicates that it is not Nothing: It contains an actual
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3/17/10 However, a QuickWatch on the AllStudents List reveals that it is
Background image of page 8
3/17/10 Fixing the Bug NOW, we can stop debugging. We know the cause of the error: We are trying to add items to a List object that doesn’t exist yet. To fix the problem, we need to create the List before using it. Assuming that we will want to use that List elsewhere in the form’s code, the best places to create it would be when the form is created.
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3/17/10 Form Load Here is the form’s code using Form Load to create the List:
Background image of page 10
3/17/10 Constructor Here is the form’s code using a custom constructor to create the List:
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
3/17/10 No Error, No Action? What if you run your program, and it seems to freeze? That is, you do not get an error message, but the program hasn’t done what it was supposed to do, and it doesn’t respond to mouse clicks? It is probably stuck in an infinite loop.
Background image of page 12
3/17/10 Debugging an Infinite Loop If this happens, the first thing to do is to switch to Visual Studio and click on the “Break All” button. (Pause)
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Break All Break All forces the program to pause execution; VB will highlight the line of code currently running. You can then step through the code
Background image of page 14
Image of page 15
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 03/17/2010 for the course IOE 373 taught by Professor Snadwich during the Winter '08 term at University of Michigan.

Page1 / 73

Lectures 17 - Assignment7Lectures - March 15, 2010 Click to...

This preview shows document pages 1 - 15. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online