Documentation

Building and Testing Our First Program

The next step is to compile the program and then we can run it. To build the program, select the Build item from the Project menu as shown below.

Building the first project

Building the first project

The compilation succeeded as can be seen in the output window:

The first project successfully compiled

The first project successfully compiled

For now we will ignore the warning from the post-processing code, but normally it is a good idea to try and deal with all of the warnings since they can otherwise result in runtime errors in the program. Now we can execute the program by either selecting the Execute item from the Project menu, or else by pressing Ctrl+E. As we can see from the picture below, the program had an error while executing.

The first project fails with an error

The first project fails with an error

Now that we have had an error, it is time to start up the debugger. Select the Start Debugging item from the Debug menu. This can also be accomplished by pressing the F4 key.

Starting the debugger

Starting the debugger

When the debugger starts, it first checks to see if the program has changed since it was last compiled and, if necessary, saves the project (if that is one of the settings) and recompiles the project. Then it initializes SIMPOL, loads and starts the program, and breaks execution on the first statement following the declaration of the main() function, as shown below:

The debugger stopped on the first statement

The debugger stopped on the first statement

To single step through the code, press F10. We will eventually get to the line shown in the picture below:

The debugger stopped on the last statement inside the function

The debugger stopped on the last statement inside the function

Pressing the F10 key once more will result in an error that looks something like the following picture:

The program is halted with an error

The program is halted with an error

The error number is 40, "Incorrect parameter type". If we take a closer look at the source code, we can see that the first parameter to the .tostr() in the final segment of the last statement is dt.seconds. The error here is the missing parentheses, since seconds() is a method of the datetime type, not a property. Let's now change the source code to the correct syntax.

The corrected program source

The corrected program source

Now by pressing Ctrl+B (or by selecting the appropriate item from the menu) we can rebuild the program and by then pressing Ctrl+E (or a valid alternative) we can execute the program. This time the program runs successfully without errors, as we can see from the resulting picture.

The program has run successfully

The program has run successfully

Upon careful examination of the output from the program, however, we can already see that there is still some improvement that can be made over the current version. The program output the string 2009/8/12 20:0:25. Although the date might be considered acceptable, the time is certainly not going to be acceptable in the current format by most people. In the next section we will improve the current program by making incremental improvements and by making use of supplied library functionality that itself was written in SIMPOL.