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?
Solved! Go to Solution.
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])
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
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.
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.
ahhh python-esque then
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.
Thank you! You're right on point.
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])
Thank you! This worked like a charm. I appreciate everyone's help.