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
2 Answers 2
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
-
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– Peter Horsbøll Møller2013年01月02日 08:35:04 +00:00Commented Jan 2, 2013 at 8:35
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