I have a polygon shapefile of land units with dozens of attributes. I use multiple attributes to label each land unit. One attribute has three possible values: "Y", "N", or " " (not NULL).
If possible, in a single label string, I would like to replace the "Y" and the "N" with different text. For example:
"Y" = "HIGH"
"N" = "LOW"
I have been able to replace one or the other successfully using a variety of different VBScripts such as this one:
Function FindLabel ([TYPECD] )
FindLabel = Replace([TYPECD],"Y","HIGH") & Replace([TYPECD],"N","LOW")
End Function
However, the result is a label that has BOTH values in it. Example: " HIGH Y" or "N LOW"
Is there a way to nest REPLACE within itself so that it replaces both "Y" and "N"?
Alternately, is there a way have one string ignore all other content besides the value I am replacing? For example, if I do HIGHStr = Replace([TYPECD],"Y","HIGH") and ignore everything else
LOWStr = Replace([TYPECD],"N","LOW") and ignore everything else
Then I could just use FindLabel = HIGHStr & LOWStr
I know I could achieve this by defining classes of features and labeling them differently. However, I am trying to implement this labeling across many layers in many different maps, so loading a single expression would go much faster.
Solved! Go to Solution.
If you're just trying to label the features as "HIGH" or "LOW", you don't need to use Replace at all.
Function FindLabel ([TYPECD] )
if ([TYPECD] = "Y") then
FindLabel = "HIGH"
elseif ([TYPECD] = "N") then
FindLable = "LOW"
end if
End Function
If you're just trying to label the features as "HIGH" or "LOW", you don't need to use Replace at all.
Function FindLabel ([TYPECD] )
if ([TYPECD] = "Y") then
FindLabel = "HIGH"
elseif ([TYPECD] = "N") then
FindLable = "LOW"
end if
End Function
Excellent! A perfect, elegant solution. Thank you. I was thinking about the
problem in the wrong way.
Rebecca Howser
"All living things on earth are kindred." ~Edward Abbey
Glad to help. Don't forget to mark the question as answered.