Select to view content in your preferred language

Label Expression Bug

1518
7
Jump to solution
04-19-2013 04:16 AM
MarkPaulson
Occasional Contributor
I have used the following example from the help file substitution my own fields:

def FindLabel ( [Parcel_No], [Owner_Name] ):   if  [Parcel_No]  >= 0:     return "<CLR red='255'><FNT size = '14'>" + unicode( [Owner_Name]) + "</FNT></CLR>"   else:     return [Owner_Name] 


The label shows in my feature class as:
      <CLR red='255'><FNT size = '14'>Doe, John & Linda</FNT></CLR>

not in the color red. It shows correctly in the verify box in the expression verification. Also, why do I have to use unicode([FIELD_NAME]) to avoid an error?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
MarkPaulson
Occasional Contributor
You need the ";" after the &amp


thanks for you help. I tried the ";" after the &amp and get a syntax error. If I put it after the ")" it labels but still the "&amp" in the name.

View solution in original post

0 Kudos
7 Replies
KenBuja
MVP Esteemed Contributor
The ampersand (&) and angle bracket (<) are special characters  and will interfere with the formatting tags. You have to replace them with code similar to this:

Function FindLabel ([LABELFIELD])
  NewString = Replace([LABELFIELD],"&","&amp;")  
  FindLabel = "<ITA>" & NewString & "</ITA>"
End Function


See the help page on formatting tags
0 Kudos
MarkPaulson
Occasional Contributor
The ampersand (&) and angle bracket (<) are special characters  and will interfere with the formatting tags. You have to replace them with code similar to this:

Function FindLabel ([LABELFIELD])
  NewString = Replace([LABELFIELD],"&","&amp;")  
  FindLabel = "<ITA>" & NewString & "</ITA>"
End Function


See the help page on formatting tags


Read that many times, but that is VBA which I know even less about than Python 🙂

tried the following:

def FindLabel ( [Owner_Name] ):
  test =  [Owner_Name].replace( '&', '&amp')
  return "<CLR red='255'>" + test + "</CLR>"


But now get:
<CLR red='255'>Mr &amp Mrs John Doe</CLR>
0 Kudos
KenBuja
MVP Esteemed Contributor
You need the ";" after the &amp
0 Kudos
MarkPaulson
Occasional Contributor
You need the ";" after the &amp


thanks for you help. I tried the ";" after the &amp and get a syntax error. If I put it after the ")" it labels but still the "&amp" in the name.
0 Kudos
MarkPaulson
Occasional Contributor
thanks for you help. I tried the ";" after the &amp and get a syntax error. If I put it after the ")" it labels but still the "&amp" in the name.


I'm an idiot! Finally put the ";" inside the quote and it worked! It's the little things that get you.
0 Kudos
MarkPaulson
Occasional Contributor
I finally got my labeling to work as I wanted: screen shot attached. Below is the code that made it work. I discovered that that having nulls in a field caused lots of problem so I just filled with dummy text. Anyway, if some one could look at the code and maybe suggest a more elegant approach I would appreciate the effort. Thanks in advance.

def FindLabel ( [Owner_Name], [Owner_St], [Parcel_No], [Owner_City], [Owner_State], [Property_ID] ):
  parcelNo = "<BOL>" + "Parcel No.: " + "</BOL>" + [Parcel_No] 
  propertyID =  propertyID = "<BOL>" + "Property ID: " + "</BOL>" + [Property_ID] 
  ownerTemp = [Owner_Name].title()
  ownerName =  "<BOL>" + "Owner: " + "</BOL>" + ownerTemp.replace( '&', '&amp;')
  streetAdd = "<BOL>" + "Address: " + "</BOL>" +  [Owner_St].title()
  ownerCity = "<BOL><CLR black = '0'>" +"Address: "+ "</CLR></BOL>" +  [Owner_City].title() 
  LF= '\n'
  strResult = parcelNo+  LF+ propertyID + LF +  ownerName +  LF +  streetAdd + LF + ownerCity + ", "+ [Owner_State] 
  return strResult
0 Kudos
KenBuja
MVP Esteemed Contributor
it worked! It's the little things that get you.


That's good to hear. Don't forget to click the check mark to signify your original question was answered.

What is the issue you're running into with the null fields? You can check for nulls and skip them if necessary.
0 Kudos