2

I have a route feature which I have set up to label every 500' with the distance along the line. I'd like to use typical stationing format (000+00). I've been using the following VBA script:

Function FindLabel ( esri__measure )
if esri_measure=0 then
    FindLabel = "0+00"
elseif   esri_measure<1000 then
     varleft = left(esri__measure, 1)
     varright = right(esri__measure, 2)
     FindLabel = varleft & "+" & varright
else
     varleft = left(esri__measure, 2)
     varright = right(esri__measure, 2)
     FindLabel = varleft & "+" & varright
end if
End Function

each "else" works properly on it's own, but when all the script is entered, the first "else" to be satisfied is applied to all labels. For instance, with the script as copied above, every distance label reads exactly "0+00". To see what happens I try changing the script to:

Function FindLabel ( esri__measure )
if   esri_measure<1000 then
     varleft = left(esri__measure, 1)
     varright = right(esri__measure, 2)
     FindLabel = varleft & "+" & varright
else
     varleft = left(esri__measure, 2)
     varright = right(esri__measure, 2)
     FindLabel = varleft & "+" & varright
end if
End Function

With this script every label is formatted "X+00". When the value is greater than or equal to 1000, I need it to read "X0+00". The problem seems to be that the program tests only the first label (distance 0) against the "if" statement, then applies the outcome to every labeled location. How do I get each label to run through the "if" statement independently rather than only testing the first point?

4

You missed an underscore in the esri__measure variable in your first 2 if clauses, so they always tested as equal to 0 and fullfilled the condition of the first clause (an uninitialized variable esri_measure will equal 0 while esri__measure is not 0). So in reality no measures were being tested in any of your clauses, just a bad variable that was always 0.

If you expect your measures to exceed 10,000 (like mine do) then your expression needs additional clauses. Mine can be as high as 150,000. The code will now work with any measure values between 0 and 999,999 and with intervals that are not divisible by 100.

Function FindLabel ( esri__measure )
if CLng(esri__measure) < 10 then
     varleft = 0
     varright = right(CLng(esri__measure), 1)
     FindLabel = varleft & "+0" & varright
elseif CLng(esri__measure) < 100 then
     varleft = 0
     varright = right(CLng(esri__measure), 2)
     FindLabel = varleft & "+" & varright
elseif CLng(esri__measure) < 1000 then
     varleft = left(CLng(esri__measure), 1)
     varright = right(CLng(esri__measure), 2)
     FindLabel = varleft & "+" & varright
elseif CLng(esri__measure) < 10000 then
     varleft = left(CLng(esri__measure), 2)
     varright = right(CLng(esri__measure), 2)
     FindLabel = varleft & "+" & varright
elseif CLng(esri__measure) < 100000 then
     varleft = left(CLng(esri__measure), 3)
     varright = right(CLng(esri__measure), 2)
     FindLabel = varleft & "+" & varright
else
     varleft = left(CLng(esri__measure), 4)
     varright = right(CLng(esri__measure), 2)
     FindLabel = varleft & "+" & varright
end if
End Function
2

Actually, since you know all your measures always end in +00, because that applies to all intervals of 500, you can simplify the expression to:

esri__measure / 100 & "+00"

You only need the more complex expression in my earlier post when your hatch intervals divided by 100 are not integer values.

That would apply if the last measure was shown whether or not it fell on an interval. However, in that case you would need to make sure all of the values were rounded to an integer prior to extracting the right two digits from the number, so I modified my previous expression to handle that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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