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:





Date Functions Sample Code


This application demonstrates the use of some Date functions - CurDate(), Day(), Month(), Weekday() and Year().

This application creates a (Non-Earth) point table, with each point having a date attached to it. The dates are taken from 16 years - the current year, the 7 previous years and the 8 years to come. The points are plotted in a calendar-like way, with 4 columns, each containing 4 years.

Please see the file below for CreateCalendar.MB and CreateCalendar.MBX.

 CreateCalendar.zip
Calendar Map with all Mondays selected

SQL Statements with Date functions


What's the use of this table? You can use it to test SQL statements with Date functions!

For example to select all Mondays:

Select * from Calendar where Weekday(Date) = 2 into Mondays


Or to select all leap days:

Select * from Calendar where Month(Date) = 2 And Day(Date) = 29 into Leap_days


Or to select the 10th day of each month:

Select * from Calendar where Day(Date) = 10 into The_Tenth



You might wish to have a look at this tool 'Query using Date Functions': it offers a dialog to query Date and/or DateTime columns.





More code samples will follow...;-)



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