Below is code but containing a few errors. If we try to compile this code it will generate a number of error messages. On this occasion I would suggest you copy and paste this code into MapBasic if you are not familiar with correcting coding errors. Normally I would always recommend typing coding samples, as you learn more through that method. However, on this occasion copying and pasting is the correct procedure.
Purpose: Show the note, print and loop facilities
' Declare
Declare Main
' Function: Main
' Purpose: Loop five times and print out a message each time
' Shows how the print, note and loop statements work
Sub Main
i As Integer
' the loop will execute a Print statement 5 times
For i = 1 to 5
Print "Hello world! The count is now " + Str$(i)
Next
' Let the user know that looping has finished
Note The loop is now finished."
End Sub
As you can see the first message states that on line four MapBasic has found an unrecognised command Show. If you double click on the error message it will take you to the relevant line. Alternatively you can use Search – Go to line from the top menu bar or use the Ctrl+T short cut option. This will open a dialogue box in which you can specify the line number you want to go to. In this case the error was a missing single quote as the line was for information purposes only. If you compile again a dialogue box asks if you want to save the changes so click OK. Again we get the error message dialogue box. The first message now refers to line 8. Found [Main] whilst searching for [Sub]. Here the correct notation should have been Sub Main. Correcting this error and recompiling shows that we have four error messages to deal with. This has happened even though we have corrected only two errors against the original ten. Fixing those two errors reduced the number of errors found significantly as seen in the screen shot below:
The error on line 18 is caused by the lack of a Dim statement. Fixing this line reduces the errors from four to two. The error at line 30 is caused by a missing double quotation mark in the Note statement. When you fix this error the final error also disappears and the code is successfully compiled.
The code below highlights the lines containing errors together with an explanation of why this causes a compile problem.
Purpose: Show the note, print and loop facilities [Missing single quote]
' Declare
Declare Main [Missing Sub]
' Function: Main
' Purpose: Loop five times and print out a message each time
' Shows how the print, note and loop statements work
Sub Main
i As Integer [Dim statement missing]
' the loop will execute a Print statement 5 times
For i = 1 to 5
Print "Hello world! The count is now " + Str$(i)
Next
' Let the user know that looping has finished
Note The loop is now finished." [Missing opening double quote ]
End Sub