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:

C# Sample Code

The C# code in this sample contains methods to convert a Date (or Date/Time) value to a Long Date string and to retrieve the name of the month or the weekday from a Date (or Date/Time) value. Thess methods can be used from your MapBasic application to get a proper date string, e.g. to use on printed output.

This sample is kept as simple as possible: it contains only one C# source file, which can be compiled into a *.dll even without installing Microsoft Visual Studio.

To compile the C# source, you can use the C# compiler - csc.exe - which is available on your machine by default. csc.exe is part of the Microsoft .NET Framework 3.5 which you need to run MapInfo Professional 9.5 or higher.

It really is a hands-on example. If you need something more of a theoretical introduction to C#: there is some information available on the world wide web :-). A nice starting point would be the website C# Station, a community site for people interested in applying .NET using the C# programming language.

Please see the file below for MBExtensions.cs, MBExtensions.dll, CallRegionalLongDate.mb and CallRegionalLongDate.MBX.
In the document below you will find a description of how to create a method in a Dynamic Link Library/.NET Assembly and use this method in your MapBasic application:

 TWIAV_TIP_MB004.pdf: Using a .NET assembly in MapBasic

Convert Date Value to Long Date String

.NET support has been introduced with MapInfo Professional 9.5

Two of the methods described here - RegionalMonth and RegionalWeekday - are applied in the tool 'Query using Date Functions'

Other examples of using .NET assemblies in your MapBasic application

More code samples will follow...;-)

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