120 likes | 561 Views
Finding & Fixing Errors. In Visual Basic 5.0. Programming errors come in three varieties:. Compile errors Run-time errors Logic errors. As VB attempts to convert your project code to machine language (called compiling the code) it finds any compile errors. You get compile errors when:.
E N D
Finding & Fixing Errors In Visual Basic 5.0
Programming errors come in three varieties: • Compile errors • Run-time errors • Logic errors
As VB attempts to convert your project code to machine language (called compiling the code) it finds any compile errors. You get compile errors when: You break syntax rules of Basic & sometimes when you use an illegal object or property (eg: ennd, Quit rather than End) use wrong punctuation or place the punctuation in the wrong place (eg: lblMessage,Caption) Compile Errors
Compile Errors (cont’d) • May be found by the editor as you move off the offending line or the compile error may not be found until you try to run the program • Inconsistent spelling of object names is most common compile error (eg: if you set a label control’s Name property to lblMessage, you MUST ALWAYS refer to it with that exact spelling!!)
Run-Time Errors • If your project halts during execution, that’s a run-time error • A dialog box will be displayed, goes into break time, and highlights the statement causing the problem • Usually caused by attempting to do impossible arithmetic operations: calculate with nonnumeric data, divide by zero, finding the square root of a negative number
Logic Errors • Your project runs but produces incorrect results… • Perhaps the results of a calculation are incorrect (incorrect formulas) or the wrong text appears or the text is OK but appears in the wrong location. • May need to use a calculator to check the output, or computations, text, spacing
Project Debugging • Programs don’t really have errors in them…they get “bugs”…finding & fixing these bugs is called debugging • VB will display the Code window with the offending line highlighted for compile & run-time errors • Must locate logic errors yourself • Remember you also have VB Help at your disposal!
How to find your errors • Check for spelling errors within your program. • Check you are using the same name in the program as the variable you defined (Dim…) • Check you have defined the variable (Dim…) and that is of the correct type (remember, integers in VB only go to ~32,000!
To solve logic errors • Create extra labels and display other values as you go. • If you use variables that are never shown, display those in extra labels • When the program works, delete the labels and code • Keep a complete list of remarks so you can delete all codes associated with the extra labels - lblExtra.captions=... etc.
Most importantly: Go one step at a time! Determine a value and display it. When that WORKS, determine the next value. DO NOT ask for help for a program that is completed but where the 1st step doesn’t work!!!!!!! I will not help you debug in this situation.