If Then Else in Label Expressions

876
2
11-29-2018 03:46 PM
JasonSmith3
New Contributor

I am having a problem with formatting text in a label expression using VBscript. 

Here is my label expression:

 

Function FindLabel ([Mean], [Count])

  if ([Mean] < 1) then

               FindLabel =   [Count] & vbCrLf & vbCrLf & "< 1" & vbCrLf & " "

  Else

FindLabel =   "<FNT size='3'>" & [Count] & vbCrLf & vbCrLf& "</FNT>" & "<BOL>" & Round([Mean],1) & "</BOL>" & vbCrLf & " "

 

  end if

End Function

 

It results with this: the label on the left is what I want. 

 

 

I understand that the cells on the right are formatted as they are because of the < formatting tags> but if I edit the label expression to have the tags on both sides of the Else statement like this:

 

Function FindLabel ([Mean], [Count])

  if ([Mean] < 1) then

               FindLabel =   "<FNT size='3'>" & [Count] & vbCrLf & vbCrLf& "</FNT>" & "<BOL>" & "< 1" & "</BOL>" & vbCrLf & " "

  Else

FindLabel =   "<FNT size='3'>" & [Count] & vbCrLf & vbCrLf& "</FNT>" & "<BOL>" & Round([Mean],1) & "</BOL>" & vbCrLf & " "

 

  end if

End Function

 

It results with this:

 

 

Is there some way around putting tags on either side of the Else statement?

0 Kudos
2 Replies
TedKowal
Occasional Contributor III

The symbols "<" , ">", and "&" are special characters and are not valid in your text if formatting tags are used. Use the equivalent character entity codes &amp; and &lt; instead....  You can find other special entity character codes here: HTML 4 Entities 

 "<FNT size='3'>" & [Count] & vbCrLf & vbCrLf& "</FNT>" & "<BOL>" & "&lt;1" & "</BOL>" & vbCrLf & " "‍
JasonSmith3
New Contributor

Thank you!   

I replaced the "<1" with "&lt;1" and that fixed it.

0 Kudos