TWIAV - Tips & tricks

TWIAV - Tips & tricks

MapBasic Code Samples

On this page you will find some MapBasic code samples, both the program source and the compiled application. Everything on this page is offered "as is" without warranty of any kind, either expressed or implied, including limitation warranties of merchantability, fitness for a particular purpose, and noninfringement.

Unless otherwise stated MapBasic 9.0 has been used to compile the files - this means that the MBXs offered here will only run with MapInfo Professional 9.0 or higher. If you want to use the tools with another (an older) version of MapInfo Professional, you will have to compile the tool using the relevant version of the Mapbasic compiler.

The MapBasic Code Samples Project

The goal of this project is to provide some examples of how to use certain MapBasic functionality - not to offer full-blown applications. The applications below each focus on one 'trick'. You can study the source, modify it to suit your needs and implement it in your own apps.

The following code samples are available here:

Modular Programming Sample Code

This application demonstrates how to set up a MapBasic project consisting of several modules.

The actual application - showing current date and current time - is not that exciting at all.

It is the source files you should be after:

  • Project.mbp

  • ProjectUI.mb, Functions.mb, ModuleOne.mb and ModuleTwo.mb

  • Project.def

You can compile the source files (*.mb) to become object files (*.mbo) and you can link the object files to become an executable application file (*.mbx).

This little app is purely meant to be an example on how to set up your own projects.
In the document below you will find a description of the building blocks of a project:

 TWIAV_TIP_MB003.pdf: Modular Programming in MapBasic

Sample Code Menu

Please see the file below for Project.mbp, ProjectUI.mb, Functions.mb, ModuleOne.mb, ModuleTwo.mb, Project.def and Project.MBX:


Using Notepad++?

If you are using Notepad++ to develop your MapBasic applications, you can configure your text editor to compile all object files, link the project file and run the resulting application, all with one mouse click or keystroke. More information can be found here.

Custom Function

In this application a custom function is used. This function - LongDate() - converts a Date into a string with weekday and month. In this document you will find description of how to create and use a custom function in MapBasic.

More code samples will follow...;-)

What do you think of these code samples? If you have any , please let me know.