jps services
  • Home Page
  • GIS Training Courses
    • QGIS Training Courses
    • ArcGIS Training Courses
    • MapInfo Pro Training Courses >
      • MapBasic Training Course
  • About
  • Blog

Fixing MapBasic coding errors

28/11/2016

0 Comments

 
No matter how carefully you code you will from time to time find that your MapBasic code will not compile. When this happens you will have one or more messages appear at the bottom of the MapBasic Development Environment window. Some of these messages are self explanatory. For example, you have failed to initialise a variable or have not included the necessary definition files. You also need to be aware that, even though your code may compile, because of logic errors it still may not perform in the way you intended. In the previous blog Creating a simple MapBasic program the code had no errors and would have compiled and run as intended.

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.
Program: SimpleCodeExample with errors
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​

Read More
0 Comments

Creating a simple MapBasic program

20/11/2016

0 Comments

 
One way to effectively learn how to code is to look at code examples and try to understand what the program is doing. Additionally, you also need to write the code into the MapBasic Development Environment to fully grasp what is going on in the code sample, rather than just reading or cutting and pasting.

Lets start by creating a simple code example which covers the Print, Note and Loop facilities within MapBasic.  Make a new file in MapBasic using File – New then save this Untitled file as SimpleCodeExample. This will create a new file called SimpleCodeExample.mb. The .mb extension on the file shows that it has not been compiled and can be used to input MapBasic code to create a new program.
Type the following into the MapBasic Development Environment:-

' Program: SimpleCodeExample
​
' Purpose: Show the note, print and loop facilities
​
By putting a single quotation mark in front of these two lines we have indicated to MapBasic that we want this to be for information only purposes. So the compiler will ignore these lines when we create an executable file.
​

Next we will put in a Declare statement which MapBasic Help states ‘declares the name and parameter list of a function’. I would recommend that you type ‘declare’ into the search facility of MapBasic Help for a full description of the Declare Function statement. In effect you have to tell MapBasic exactly what you are going to do at every stage. An example of this is the use of the Declare statement.

Read More
0 Comments

    Author

    Joe Short BSc has been involved with various mapping solutions for over twenty years.  If you are considering implementing a GIS  or have ArcGIS Pro, MapInfo Pro or QGIS training requirements, jps services would be happy to be of assistance to your organisation. 

    Archives

    April 2020
    March 2020
    October 2019
    September 2019
    August 2019
    July 2019
    March 2019
    November 2018
    October 2018
    August 2018
    July 2018
    November 2017
    October 2017
    September 2017
    July 2017
    February 2017
    January 2017
    December 2016
    November 2016
    October 2016
    May 2016
    February 2016
    September 2015
    August 2015
    April 2015
    February 2015
    November 2014
    October 2014
    July 2014
    June 2014
    May 2014
    March 2014
    February 2014
    December 2013
    November 2013
    October 2013
    September 2013
    August 2013
    June 2013
    May 2013
    April 2013
    February 2013
    December 2012
    October 2012
    September 2012
    August 2012
    July 2012

    Categories

    All
    Arc Gis
    Arcview
    Autodesk
    Cad
    Gis Training
    Local Government
    Mapbasic
    Mapinfo
    Quantum Gis
    Relational Databases
    Saga Gis

    RSS Feed