Pete:
You said
>I am presently stuck with the following problem, it is starting to
drive me
>nuts, and I am sure I am missing something embarrassingly obvious!
>nuts, and I am sure I am missing something embarrassingly obvious!
>In Mapbasic/Mapinfo 5 I am trying to use the Set Map Statement to
label a
>layer where the layer_id is a string variable
>layer where the layer_id is a string variable
Your problem arises because:
1) the MapBasic language does not consistently allow general
expressions in its statements at places where user-supplied values are
required
2) exceptions are not documented in either the on-line help or the
reference manual.
By "general expression" I mean the use of combination of
literals, variables and operators that evaluates to either a numeric or string
value as required by the context. Your string variable
"layer-id" fits this description.
For example, the syntax for the center clause in MapBasic set map is:
Set Map
[ Window window_id ]
[ Center ( longitude, latitude ) [ Smart Redraw ] ]
[ Window window_id ]
[ Center ( longitude, latitude ) [ Smart Redraw ] ]
where the place-holders window-id, longitude and latitude denote
user-supplied values.
By trial-and-error you can establish that the longitude and latitude
"places" may be successfully filled in with expressions involving
variables like:
set map window frontwindow() center ( x+150,y-35)
The syntax for the label-with clause in the MapBasic set map appears quite
similar:
Set
Map
[ Window window_id ]
[ Layer layer_id
[ Label
[ Window window_id ]
[ Layer layer_id
[ Label
[ With label_expr ]
]
]
]
where the tokens window-id, layer_id and label_expr again
denote user-supplied values.
However, as you found out by-trial-and-error, the use of a variable in the
label_expr "place" is not successful. Although it does not lead to a
compile-time syntax error, the labels don't appear at all when you try
this:
dim
strField
strField="StateName"
set map window frontwindow()
set map window frontwindow()
Layer "Australia"
Label with
strField
In my experience, SQL SELECT statements, SET
MAP statements and THEMATIC SHADE statements are all prone to this kind of
problem.
The general work-around is to write code to pre-expand these troublesome
statements into string variables at run-time and then execute them in
"immediate mode". Like this:
'
settest.mb
declare sub
main
sub main
dim s_Country as
string
dim s_Label_layer as string
dim s_Label_field as string
dim strStatement as string
dim s_Label_layer as string
dim s_Label_field as string
dim strStatement as string
s_Country="D:\mapdata\bdys\general\austrlia\austrlia.tab"
s_Label_layer = "Austrlia"
s_Label_field = "StateName"
close all
open table s_Country as austrlia
map from austrlia
s_Label_layer = "Austrlia"
s_Label_field = "StateName"
close all
open table s_Country as austrlia
map from austrlia
' pre-expand
statement
strStatement=
"Set Map window frontWindow() " +
"Layer " + s_Label_layer +
" Label " +
" Font (""Arial"",256,8,0,16777215) " +
" Line Simple " +
" Position Center " +
" With " + s_Label_field +
" Auto On "
' execute statement in immediate mode
run command strStatement
strStatement=
"Set Map window frontWindow() " +
"Layer " + s_Label_layer +
" Label " +
" Font (""Arial"",256,8,0,16777215) " +
" Line Simple " +
" Position Center " +
" With " + s_Label_field +
" Auto On "
' execute statement in immediate mode
run command strStatement
end
sub
Regards
David M
Haycraft
Phone/Fax: 61 + 2 + 6231 8104
Information Analysis Assocs P/L Mobile: 0412 001 134
ACN 085 516 105 Email: [EMAIL PROTECTED]
1 Cumming Place, Wanniassa
A.C.T. 2903, Australia A MapInfo Partner
Information Analysis Assocs P/L Mobile: 0412 001 134
ACN 085 516 105 Email: [EMAIL PROTECTED]
1 Cumming Place, Wanniassa
A.C.T. 2903, Australia A MapInfo Partner
