How can I combine both CLR and VBNewline in my Label Expression?

2028
8
Jump to solution
03-20-2019 04:26 PM
SalWebber
New Contributor

I am creating a label style that needs to contain three pieces of information from three attribute fields in the feature class. In the label expression, each field needs to appear on its new line, and one field [GW_Elevati] needs to appear in blue font. 

In my first draft, I used only the &vbnewline& command, and it came out just fine. However, when I added in the appropriate code for coloring the font (see code below), I got this:

[Location]&vbnewline & "<CLR blue = '255'>" & [GW_Elevati] & "</CLR>" &vbnewline&[Carbon_tet]

In the next stage, I found that if I added in a single quotation mark after the close of the CLR code, I got this result:

[Location]&vbnewline & "<CLR blue = '255'>" & [GW_Elevati] & "</CLR>"' &vbnewline&[Carbon_tet]

As you can see, it colors the appropriate text, but drops off the final attribute field/text. 

I've tried opening and closing quotes around different parts of the expression, but can't seem to get the result I'm looking for. Any advice?

0 Kudos
1 Solution

Accepted Solutions
TedKowal
Occasional Contributor III

As Randy Burton  mentioned... your  "<" in the carbon field must be escaped.  In Vbscript there is no escape character as in python, for vb you must double quote the field that has the character(s) that need escaping.  

[Location]& vbcrlf & "<CLR blue = '255'>" & [GW_Elevati] & "</CLR>" & vbcrlf & "" & [Carbon_tet]& """

# Or use the vb escape function


....  vbcrlf & escape([Carbon_tet]) 

View solution in original post

8 Replies
DanPatterson_Retired
MVP Emeritus

you have this in 'python snippets' there is no vb place.  If you are looking for a python newline character it is \n

print('a' + '\n' + 'b')
a
b

0 Kudos
SalWebber
New Contributor

Thank you. I couldn't quite figure out where VBScript should be posted. Do you have any recommendations? I'll give the Python newline script a try as well.

0 Kudos
RandyBurton
MVP Alum

And in the Label Expression dialog, you need to use  the \r\n pair for a new line with Python.  It is one of the few places in Desktop where \n alone won't work as expected.

0 Kudos
DanPatterson_Retired
MVP Emeritus

ahhh python-esque then

0 Kudos
RandyBurton
MVP Alum

I suspect the issue might be with the <0.50 value in the Carbon_tet field.  You may have to escape the less-than symbol because you are using the "html-like" CLR tag.  A greater-than symbol would also need escaping.

SalWebber
New Contributor

Thank you! You're right on point.

0 Kudos
TedKowal
Occasional Contributor III

As Randy Burton  mentioned... your  "<" in the carbon field must be escaped.  In Vbscript there is no escape character as in python, for vb you must double quote the field that has the character(s) that need escaping.  

[Location]& vbcrlf & "<CLR blue = '255'>" & [GW_Elevati] & "</CLR>" & vbcrlf & "" & [Carbon_tet]& """

# Or use the vb escape function


....  vbcrlf & escape([Carbon_tet]) 
SalWebber
New Contributor

Thank you! This worked like a charm. I appreciate everyone's help.

0 Kudos