Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a query regarding the Mapbasic feature of MapInfo, I want to change the line style of an item depending on name (e.g if the .tab name contains the world group). I think I can work this out with a few bits of syntax help. So for example if I change one tab this appears in the MapBasic window

Set Window 376609128 Front
Set Map Window 376609128  Layer 10 Display Global    Global Line (2,2,16711680)    Arrows On

Would I need to write a statement similar to if contains "xx" then do that? I have a very basic knowledge of scripts syntax but is my basic understanding correct, would this be the way to do it?

Thanks, Alan

share|improve this question
*word not world – Alan Carr Dec 17 '12 at 10:29
up vote 2 down vote accepted


I assuming that you have a map with a number of layers and that you want to change the override style of certain layers if their name contains a certain text, correct?

You could build a loop like this:

Include "MapBasic.def"

Dim nMID, nLayer As Integer,
    sLayer As String

nMID = FrontWindow()
For nLayer = 1 To MapperInfo(nMID, MAPPER_INFO_LAYERS)
    sLayer = LayerInfo(nMID, nLayer, LAYER_INFO_NAME)
    If sLayer Like "%xx%" Then
        Set Map Window nMID
            Layer nLayer 
                Display Global Global Line (2,2,16711680)
                Arrows On
    ElseIf sLayer Like "%yy%" Then
        Set Map Window nMID
            Layer nLayer 
                Display Global Global Line (2,2,16711680)
                Arrows On
    '**add extra cases here below if you need to
    '**ElseIf sLayer Like "%zz%" Then
    '**    Set Map Window nMID
    '**        Layer nLayer 
    '**            Display Global Global Line (2,2,16711680)
    '**            Arrows On
    End if

Above I test the name of the table against a certain condition. You could also use the name of the tab file of the layer by replacing

sLayer = LayerInfo(nMID, nLayer, LAYER_INFO_NAME)


sLayer = LayerInfo(nMID, nLayer, LAYER_INFO_PATH)

This is from the top of my head and I have not tested it, so it might need a bit tweaking.

share|improve this answer
Thanks, I'll take a look at this now! – Alan Carr Dec 17 '12 at 13:31
Peter, I get the errors: Variable nMID not defined and Loop control variable not defined – Alan Carr Dec 17 '12 at 13:48
Never mind, got around that now, but when I come to run it in MapInfo I am getting: Variable or Field MAPPER_INFO_LAYERS not defined – Alan Carr Dec 17 '12 at 14:18
Alan, I have modified the answer to also have the line for including the file MapBasic.def. Sorry that I forgot that in my first response – Peter Horsbøll Møller Dec 18 '12 at 18:20
Thank you! This has both sped up some aspects of my work, and impressed my boss! – Alan Carr Dec 21 '12 at 10:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.