Label Expression

2764
8
08-31-2022 08:51 AM
lindajo04
Emerging Contributor

If the [Situs_Unit] field is blank on the parcel layer I would like the # sign to not show on the map labeling.  Is there a way this can be accomplished?

This is my label expression for my parcel layer.  [Situs_Num] & " " & [Situs_St] & " # " & [Situs_Unit].  If the parcel has info in this field, [Stius_Unit], it looks like this:  103 Park #421.  If the parcel has no info in the unit field it looks like this:  124 Park #.  is there a way in the expression to remove the # sign if the field is blank?

Thank you,

 

Linda Jo

0 Kudos
8 Replies
jcarlson
MVP Esteemed Contributor

Any label expression language should allow you to use a conditional statement to build your label. It looks like you're using VBScript, is that right? I wouldn't know the specifics for that, if there's a particular reason you need VBScript, but it's fairly straightforward.

- Josh Carlson
Kendall County GIS
0 Kudos
lindajo04
Emerging Contributor
Thank you for your feedback. When I try the expression this is what I get:
[cid:image001.png@01D8BDE8.A6716020]
[cid:image002.png@01D8BDE8.A6716020]
Any thoughts on what I did wrong?
0 Kudos
KenBuja
MVP Esteemed Contributor

Can you reload those images?

0 Kudos
KenBuja
MVP Esteemed Contributor

You can build the label using VBScript this way

Function FindLabel ( [Situs_Num], [Situs_St], [Situs_Unit] ) 
  FindLabel = [Situs_Num] + " " + [Situs_St]
  if ( [Situs_Unit] <> null ) then 
    FindLabel += " #" + [Situs_Unit]
  end if
End Function
0 Kudos
lindajo04
Emerging Contributor
Here is the response I get using the suggested code. Can you help me with what I did wrong?

[cid:image001.png@01D8BE08.8D43DB80][cid:image002.png@01D8BE08.8D43DB80]


0 Kudos
KenBuja
MVP Esteemed Contributor

Unfortunately, the images that you're uploading don't seem to be working properly.

0 Kudos
lindajo04
Emerging Contributor

lindajo04_0-1662068519812.pnglindajo04_1-1662068535445.png

Here are the images I have been trying to send you.

0 Kudos
KenBuja
MVP Esteemed Contributor

I had forgotten that VBScript doesn't have an incremental operator (+=).

Function FindLabel ( [Situs_Num], [Situs_St], [Situs_Unit] ) 
  FindLabel = [Situs_Num] + " " + [Situs_St]
  if ( [Situs_Unit] <> null ) then 
    FindLabel = FindLabel + " #" + [Situs_Unit]
  end if
End Function

Is then field [Situs_Unit] a numeric field and does it have a null value or is it a string field with an empty string?

0 Kudos