Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am currently working on a code to apply a variety of different changes to layers with certain attributes, I have been successful with this so far (thanks to Peter). However I now want to add a text box to this so the user can enter the name of the field they want labeling (as this is the only thing differs in the .TABs I intend to use this tool for).

I have currently created a dialog box for the user to input this however when it comes to labeling (I assume), MapInfo is looking for a field with the same name as my string to label with, instead of looking at what is stored there.

For example

Dim sLabinput As String


Set Map Window nMID
            Layer nLayer 
                Display Global Global Line (2,2,16711680)
                Arrows On
                    Label With sLabinput Auto On Visibility On
                    Font ("Arial",257,9,0,16777215)

I haven't put the rest of the code as I want to try and learn this myself however if that is the only way to solve it I can post it.

Am I right in assuming in this instance MapInfo is looking for a field called sLabinput, rather than the value stored in there?

Thanks, Alan

share|improve this question
add comment

2 Answers

Never mind. Managed to play around with the code and an answer from somewhere else. I'm going to post it in case

Include "MAPBASIC.DEF"

Dim sLabinput As String

Dialog
    Title "Section Ref"
    Control statictext
        Title "Enter section ref field"
    Control edittext
        Value sLabinput
        into sLabinput
    Control OKButton
    Control CancelButton

if commandinfo (CMD_INFO_DLG_OK) then

Else
End Program
End if

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 "%AllG%" Then
        Set Map Window nMID
            Layer nLayer 
                Display Global Global Line (1,2,45056)   
    ElseIf sLayer Like "%roup0%" Then
        Run Command "Set Map Window " & nMID & " Layer " &nLayer
            & " Label With " & sLabinput
            Set Map Window nMID
            Layer nLayer 
                Display Global Global Line (2,2,16711680)
                Arrows On
                  Label Auto ON Font ("Arial",257,9,0,16777215)




    '**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
share|improve this answer
    
Good to see my suggestion worked, Alan. Another way might be to use an Alias variable to hold a combination of the table and column name: –  Peter Horsbøll Møller Jan 2 '13 at 8:35
add comment

Good to see my suggestion worked, Alan.

Another way might be to use an Alias variable to hold a combination of the table and column name:

Dim aLabel as Alias
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 "%AllG%" Then
        Set Map Window nMID
            Layer nLayer 
                Display Global Global Line (1,2,45056)   
    ElseIf sLayer Like "%roup0%" Then
        aLabel = sLayer & "." & sLabinput
        Set Map Window nMID
           Layer nLayer
             Label With aLabel
        Set Map Window nMID
           Layer nLayer 
              Display Global Global Line (2,2,16711680)
              Arrows On
              Label Auto ON Font ("Arial",257,9,0,16777215)

    '**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

If it works, you can use a single Set Map statement instead of two separate statements - not that that will make a big difference

share|improve this answer
add comment

Your Answer

 
discard

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.