MapBasic – Lists of tables and windows

MapBasic is as powerful as it is frustrating. There’s no built-in way to get a list of open tables, so I’ve written some code that does just that.

First I’ll explain how to populate an array with a list of table names and numbers, then how to select a table from this list using a dialogue box, then I’ll package it all nicely into a sub and a function so that you will only need a couple of lines of code. If you don’t want to understand and just want to DO things then just skip to the last section!

Getting a list of all open tables
This is fairly simple. NumTables() returns the total number of tables opened. All open tables are numbered sequentially, starting from 1. Therefore we just need to loop through, from 1 to NumTables() and put all the names into an array, making each name’s array index value correspond with its MapInfo table number. Like so:

    Dim i as integer
    Dim j as integer
    i = NumTables()
    Dim TableArray(1) as String
    ReDim TableArray(i)
    For j = 1 to i
        TableArray(j) = Tableinfo(j, TAB_INFO_NAME)

Choosing a table via a dialog
Now that you have a variable (TableArray) that contains a list of all open table names with corresponding numbers. This can then be used in dialog boxes, for example in a drop-down menu (or as MapBasic calls it, a pop-up menu):

    Dim TableNum as Integer
    Dim TableName as String
        Title "Choose table"
        Control PopupMenu
            Title From Variable TableArray
            Into TableNum
        Control OKButton
        Control Cancelbutton

    If CommandInfo(CMD_INFO_DLG_OK) Then
        TableName = TableArray(TableNum)
        Note "You chose: " & TableName
    End If

Choosing a table with a sub and a function
MapBasic functions cannot return arrays. Therefore you must create an array variable to store the list and then use a sub to insert the data into the array.

Here are is everything above packaged into a sub and a function.

Sub GetTableList (TableList() as String)
    Dim i as integer
    Dim j as integer
    i = NumTables()
    ReDim TableList(i)
    For j = 1 to i
        TableList(j) = Tableinfo(j, TAB_INFO_NAME)
End Sub

Function ChooseTable As String
    Dim TableNum As Integer
    Dim TableArray(1) As String
    Call GetTableList(TableArray)
        Title "Choose table"
        Control PopupMenu
            Title From Variable TableArray
            Into TableNum
        Control OKButton
        Control Cancelbutton
    If CommandInfo(CMD_INFO_DLG_OK) Then
        ChooseTable = TableInfo(TableNum, TAB_INFO_NAME)
    End If
End Function

…and here is how you would use them to choose a layer:

Dim TableName as String
TableName = ChooseTable()

…and here’s how you’d get an array of table names.

Dim TableArray(1) as String
Call GetTableList(TableArray)

You can’t get much easier than that… and if you can I’d like to know how you did it!

You can use exactly the same procedure to get a window name or a list of windows. You just need to swap “table” for “window” and “TAB” for “WIN” (literally – a search and replace will work).

Posted in Uncategorized | Tagged , , | Leave a comment

List Writer and Terminal Illness

“Illness” in the Hip Hop sense of the word and “terminal” in the Linux sense of the word. Don’t rejoice, I’m not dying yet! But first…

List Writer

This is a tiny and straightforward function but I have a feeling it’s going to come in useful, so I’ll put it here for safe keeping. It takes an array and simply writes it out as you would in English. There is an example below.

     * Writes an array as a list in proper English. Commas and all.

    function write_list($arr){
        $size = sizeof($arr); 
        $n    = 1;
        $out  = '';
        foreach($arr as $item){
            if ($n == $size){
                $out .= ' '.$item;
            } else if ($n == ($size-1)){
                $out .= ' '.$item.' and';
            } else {
                $out .= ' '.$item.',';
        return $out;
    $list = array(  'Queen Elizabeth II',
                    'a paperweight',
                    'a feeling of ennui',
    echo 'In my bag I have '.write_list($list) . '. It\'s quite a big bag.';

The above would output the following:

In my bag I have Queen Elizabeth II, a paperweight, Batman, a feeling of ennui and Switzerland. It's quite a big bag.

Terminal Illness
My main coding project at the moment (apart from the big one, which I’m not allowed to talk about…more on that another time) is a web page that looks and acts like a command-line. I started this after looking at, the unofficial Google command line. “How would you go about making that, then?” a friend asked. And I thought about it. “Like this”, I said and 5 minutes later I had a basic mock-up.

Since then it has gone through a number of iterations. I have now condensed and generalised it into a re-usable class that is easy to expand and customise. It’s not quite ready for public consumption yet but as soon as it is I will release the source code.

I am also using creating a text-based adventure MMO game based on this system… More about that soon.

Edit: oh, you’ll probably want a link!

Posted in Uncategorized | Tagged , , | Leave a comment


Please grammar you’re sentences are correct so I can read at them with more easily and reply accurate.

Posted in Uncategorized | Tagged | Leave a comment

Fucking Linux – How Does That Work?

I’ve used Linux here and there for almost a decade now. Whilst it makes a lot more sense now than it did at first I still find some of it baffling. Sure, I know what bash is; I know how to ls, cp, man, cp and rm. I even know how to partition my drives appropriately for a new installation. But earlier today I was installing Ruby and realised I still feel a bit like a Windows user in a foreign land. Where were the files for ruby actually being created? Where is my Program Files folder? And what the hell is /etc?

So I started looking at the Linux file system and tried to put it into words for a Windows user. Here are some basic answers that might come in handy. They might not be 100% technically accurate – and I know there are parts that will make people who do understand it properly wince – but it will hopefully give you (a Windows user) a better idea of the big picture than a technical description would. And from there you will know how to find out more accurate and detailed information. At least that’s the plan.

One thing you have to understand before reading on is that Linux and Windows are different. If you try and treat one like the other you will probably run into trouble. A lot of this article is therefore kind of lies-to-children.

The Directory Structure

The most noticeable difference between Windows and Linux is that Linux doesn’t use drive letters. All connected media forms part of the overall file-system. This means you can have all your programs on one hard disk and all your files (E.g. /home) on another disk and it will all look like the same system. The reason for this is that Unix – which Linux is based on – was originally designed for large mainframe computers that were used simultaneously by multiple users across a whole company. In this way someone could replace the drive that held /home from a backup and nobody would notice a difference.

/ (Just a slash. AKA root.)
This is as high as you can go. This is the root directory of the whole file system. Comparable to a combination of “C:/” and “My Computer” on Windows (remember: Linux works differently!)

This is where everyones personal files are stored. Each user has a folder inside this. E.g. /home/mrchimp Analogous to “C:/users/mrchimp/” or “C:/Documents and Settings/mrchimp/“.

This is where CDs, and other removable media appear when inserted/connected to your machine.

Temporary files. This gets emptied when you reboot.

Essential system binaries that are required to boot e.g. init, ip, mount.

Essential command binary files (think EXEs and DLLs) e.g. cat, ls, cp.

Libraries essential for the contents of /bin and /sbin.

Files used to boot the system. Stores any boot loaders such as GRUB or LILO.

Stores “device files”. These are special files which are kind of like links to hardware that are stored as files. E.g. /dev/hda – points to the first hard disk; /dev/fd – points to the floppy disk. /dev also holds pseudo devices such as /dev/null which accepts and discards input and produces no output or /dev/random which produces a stream of random data.

Originally this folder was for “everything else”, hence the name. These days however it’s used for host-specific system-wide configuration files. Think “Editable Text Configuration” and you’ll be on the right lines. This is a low-risk folder – you might break things but they’ll probably be fixable – think editing a .ini file in Windows.

This is probably the closest thing to a Program Files folder that you will find but that’s probably misleading to say it like that. This is where the read-only program files go, kind of like the EXEs and DLLs that you would install on Windows. See also /var.

This is (sort of) where the rest of your program files go, namely the files which are expected to change while the program is being run – e.g. logs, caches, draft emails etc.

Posted in Uncategorized | Tagged , | 5 Comments – Opening up government is opening up the government like the hands of goatse. makes access to data easy by providing a list of links to other pages which link to PDFs which have embedded links to excel files in them. What could possibly be simpler?

I guess I should be glad that I live in a country open enough to release this data, albeit in a roundabout way. Thanks to the Freedom of Information Act we can ask them just how much this site cost us, and they will say “mumble mumble mumble”.

Posted in Uncategorized | Leave a comment

Selecting a word

This is just a little thing and it’s kind of obvious but…

Sometimes you want to select a word, so you double click on it.

Now you’ve got the word selected and probably a space at the end of the word as well.

If you double click and hold down and drag to the left you can select just the word. Drag a bit further and you can select the space to the left. It’s so simple and obvious but I’ve always either double-clicked or dragged from the start to the end, which is just fiddly. I need to get out more :/

Posted in Uncategorized | Tagged | Leave a comment

Google Street View Overlap Fail


Posted in Uncategorized | Leave a comment