19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

APPENDIX D<br />

VISUAL BASIC DEBUGGING TOOLS<br />

Errors in programs are called bugs <strong>and</strong> the process of finding <strong>and</strong> correcting them is called<br />

debugging. Since <strong>Visual</strong> <strong>Basic</strong> does not discover errors due to faulty logic, they present<br />

the most difficulties in debugging. One method of discovering a logical error is by deskchecking,<br />

that is, tracing the values of variables on paper by writing down their expected value<br />

after “mentally executing” each line in the program. Desk checking is rudimentary <strong>and</strong> highly<br />

impractical except for small programs.<br />

Another method of debugging involves placing Print methods at strategic points in the<br />

program <strong>and</strong> displaying the values of selected variables or expressions until the error is<br />

detected. After correcting the error, the Print methods are removed. For many programming<br />

environments, desk checking <strong>and</strong> Print methods are the only debugging methods available to<br />

the programmer.<br />

The <strong>Visual</strong> <strong>Basic</strong> debugger offers an alternative to desk checking <strong>and</strong> Print methods. It<br />

allows you to pause during the execution of your program in order to view <strong>and</strong> alter values<br />

of variables. These values can be accessed through the Immediate, Watch, <strong>and</strong> Locals windows,<br />

known collectively as the three Debug windows.<br />

THE THREE PROGRAM MODES<br />

At any time, a program is in one of three modes[\m]design mode, run mode, or break mode.<br />

The current mode is displayed in the <strong>Visual</strong> <strong>Basic</strong> title bar.<br />

Title bar during design time.<br />

Title bar during run time.<br />

Title bar during break mode.<br />

At design time you place controls on a form, set their initial properties, <strong>and</strong> write code.<br />

Run time is initiated by pressing the Start button. Break mode is invoked automatically when<br />

a run-time error occurs. While a program is running, you can manually invoke Break mode<br />

by pressing Ctrl+Break, clicking on Break in the Run menu, or clicking on the Break icon<br />

(located between the Start <strong>and</strong> Stop icons). While the program is in break mode, you can<br />

use the Immediate window to examine <strong>and</strong> change values of variables <strong>and</strong> object settings.<br />

When you enter Break mode, the Start button on the Toolbar changes to a Continue button.<br />

You can click on it to proceed with the execution of the program.<br />

Appendix D 457

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!