Presentation is loading. Please wait.

Presentation is loading. Please wait.

AVCE ICT – Unit 7 - Programming Session 12 - Debugging.

Similar presentations


Presentation on theme: "AVCE ICT – Unit 7 - Programming Session 12 - Debugging."— Presentation transcript:

1 AVCE ICT – Unit 7 - Programming Session 12 - Debugging

2 Error prevention This is a much better technique than “firefighting” the bugs that a program might have Try to anticipate how users will interact with your program Build the interface such that it prevents them from clicking the wrong control at the wrong time Disable them or set the visible property to false

3 Error detection Run the program when you change something and see if a bug appears Since VB is interpreted, it stops at a line it can’t execute You can then debug that particular line (highlighted in yellow) Such errors are called run time errors

4 Syntax errors VB won’t allow these! “Went I to the yesterday supermarket” Is a nonsense sentence but you can guess at the meaning VB can’t guess, you have to put the commands in the right order and use the correct spelling Syntax errors are highlighted in red

5 Logic errors These are often the hardest to deal with The program runs fine but it isn’t doing what you wanted The only way to deal with these errors is to know what was expected For example – work out a calculation first, run the program and make sure that the answer is the same

6 How to deal with errors Assuming you can’t prevent all of them…. When an error occurs, VB returns an error code e.g. 13, the type mismatch error You can use that code to deal with error using the Err function

7 How to deal with errors A typical error handler might be: If Err=13 Then MsgBox “Enter a whole number please” End If Error handlers can either be in the sub procedure itself as part of it, as a general procedure if you know that you might want to use it many times Or as a separate part of a sub procedure that the program branches to when an error occurs

8 Using the debug facilities You can set watches to observe variable values at run time You can use the Immediate window to enter values “on the fly” at run time and see how the program reacts You can execute the program by stepping into it and executing one line at a time You can set Breakpoints (marked in brown) where the program execution will stop allowing you to check values and conditions

9 Debugging versus good coding Good programming practice means that you prevent errors wherever possible Declare all variables and use option explicit Use local variables wherever possible Use indentation and comments This makes code easier to follow Be systematic in your testing

10 Your assignment To get the highest marks, you will have prevented errors or developed error handling routines You program need not be perfect – we are marking good programming and that it matches the user requirements When in doubt – keep it simple!

11 A few debugging thoughts You write a program to add two variables but keep getting the answer as 0 What could be the problem? I need to analyse the population statistics for Worcester I am using an Integer data type – why do I keep getting problems? My computer crashes when I run my program with a loop in it I am using an Input Box to read in a number but I keep getting the “type mismatch” error

12 Return to Main menu


Download ppt "AVCE ICT – Unit 7 - Programming Session 12 - Debugging."

Similar presentations


Ads by Google