1

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

1
  • *word not world
    – Alan Carr
    Commented Dec 17, 2012 at 10:29

1 Answer 1

2

Alan

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
Next

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)

with

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.

4
  • Peter, I get the errors: Variable nMID not defined and Loop control variable not defined
    – Alan Carr
    Commented Dec 17, 2012 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
    Commented Dec 17, 2012 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 Commented Dec 18, 2012 at 18:20
  • Thank you! This has both sped up some aspects of my work, and impressed my boss!
    – Alan Carr
    Commented Dec 21, 2012 at 10:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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