Test & Debug Program
Previous  Top  Next

Advanced study programs written in Visual Basic or AnyLanguage can be run and tested for errors using the debug feature of AnyLanguage. When the analysis code is displayed in AnyLanguage, the "Debug" menu becomes active, the toolbar becomes functional and an additional column displays at the left. (See the Enter/Edit Program topic for information on reaching this point.)

anylanguage



The Toolbar
(Use these tools or the Debug menu options to proceed.)

editico


The debugging process involves running selected portions of the program or stepping through it one line at a time in order to find the line that is causing the run to fail. It greatly reduces the time and effort needed to get your program running smoothly. The steps to debugging are outlined below.

1) Set Breakpoints

A breakpoint is any line of code you select for stopping a run of your program. Breakpoints can be useful to test your code up to a certain spot, but to go no further. This allows you to avoid known or suspected problems later in the file. Breakpoints also let you quickly pass over portions of the program that you know are correct so that you can spend your time stepping through only portions that are in question.

To set a breakpoint, click the blue button to the left of the first line to be excluded from the run. The button changes to a check mark and the line of code is displayed in red. Alternately, click any line of code and then pull down the "Debug" menu and select "Add Breakpoint" or click the "Set Breakpoint" icon from the toolbar. (It looks like a raised hand.) Set as many breakpoints as desired. There are three breakpoints in the above example.

To remove a breakpoint, click the check mark. Alternately, you can select the desired line of code and click "Remove Breakpoint" from the "Debug" menu or click the "Remove Breakpoint" icon. (It looks like a raised hand with an "X" through it.)

Breakpoints are not needed if you'll be stepping through the entire program one line at a time (see step 3).

2) Run the Program

If you have set one or more breakpoints, you can test your program up to the first break by clicking the [Run] button or the "Run" icon (first on the left) or by pulling down the "Debug" menu and clicking "Run." Before running your program, be sure that all necessary parameters have been inserted in the expression line.

The program will either run successfully or report an error. If it runs successfully, you'll know that there are no errors in the tested portion of the program and you can run the next portion to search for the problem.

If an error message displays, you can either run the program again after setting another breakpoint to narrow your search or return to the top and begin stepping through the code one line at a time.

3) Step Through the Code

AnyLanguage allows you check each successive line of the program to identify the precise line that is causing the failure. You may begin stepping through from the beginning of your program or you might just step through a section that has been identified by using break points. For short programs, a complete step through may be most appropriate.

The step-through options are:

·Step Into: This is the most detailed check of program. Use this command to run each line individually. If the line of code requires another function call, then the first line of the function will be run. If an error message displays, then you have found a problem with your code. If no error message displays, then you may continue stepping through in search of the error.  

·Step Over: Use this command to run your code without stepping through subroutines. This can save you time if you are using subroutines that you know are correct.  

·Step Out Of: Use this to step through the current subroutine and stop at the next line.  

·Step Until: Use this to set a temporary breakpoint and to step through the program until an error is reached or the breakpoint is reached.  

·Start With: The "Start With" option on the "Debug" menu lets you select a starting point for your step through. Use this feature to avoid stepping through areas of code that you know are correct.  

4) Correct Programming Errors


Each time the debugger reports an error, you should examine and correct the problem or problems within the given line. Re-check the line by using "Step Into." After fixing an error, you may either continue stepping through the program or run the whole program.

5) Test By Running the Program


When you think you have solved the problem with your code, click the [Run] button to see if any new or unexpected problems occur. A successful run will report no error messages and return you to the "Choose Study" screen. Click [OK] to display the chart.

Additional Run Options

·Pause: Stop at the current line. Click [Run] again to resume from the current spot.  

·Stop: End the run.  

·View Variable: Not yet functional.  

·Add Watch: Not yet functional.  

When you are sure that your program is functioning correctly, consider if it is a candidate for Optimization.