1

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.

enter image description here

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:

enter image description here

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

2

The problem is to do with your "< 1", you have used a < symbol which if you think about it is the opening character of any of your html font tags. So you've essentially opened a tag, not said what it was and not closed it correctly. Hence the weirdness you are getting.

So how do you display a symbol as text which is also a special character? You replace it with the html version of it, see this page.

So by replacing < with &lt; I see the < symbol in the label and I am creating correctly structured syntax.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.