Select to view content in your preferred language

VBScript Label Expression ArcGIS Pro Fail

580
2
Jump to solution
06-29-2023 12:20 PM
JosephPilkington1
New Contributor II

Tried my best at a VBScript label expression in ArcGIS Pro. The expression is 'valid', but the results are that nothing labels at all. Basically, I want my address points to only label with the [Address] field, when [Building] and [Unit] are both null. If [Building] is not null, but [Unit] is null, I want the label to display the [Address] followed on the next line by the [Building]. If [Unit] is not null, but [Building] is null, I want the label to display the [Address] followed on the next line by the [Unit]... if that makes sense.

I appreciate any help! My function is written as  follows:

 

Function FindLabel ( [Address], [Building], [Unit] )

If (IsNull[Unit]) And (IsNull[Building]) Then
FindLabel = [Address]

ElseIf (Not IsNull[Building]) And (IsNull[Unit]) Then
FindLabel = [Address] + vbNewLine + [Building]

ElseIf (IsNull[Building]) And (Not IsNull[Unit]) Then
FindLabel = [Address] + vbNewLine + [Unit]

End If
End Function

0 Kudos
1 Solution

Accepted Solutions
KenBuja
MVP Esteemed Contributor

There's a problem where the validator is not catching the errors where you are leaving off parentheses in the IsNull functions. Instead of "IsNull[Unit]", it should be "IsNull([Unit])"

Your code should look like this

Function FindLabel ( [Address], [Building], [Unit] )
  If (IsNull([Unit])) And IsNull([Building])) Then
    FindLabel = [Address]
  ElseIf (Not(IsNull([Building])) And IsNull([Unit])) Then
    FindLabel = [Address] + vbNewLine + [Building]
  ElseIf (IsNull([Building]) And Not(IsNull([Unit]))) Then
    FindLabel = [Address] + vbNewLine + [Unit]
  End If
End Function

 

 

View solution in original post

2 Replies
KenBuja
MVP Esteemed Contributor

There's a problem where the validator is not catching the errors where you are leaving off parentheses in the IsNull functions. Instead of "IsNull[Unit]", it should be "IsNull([Unit])"

Your code should look like this

Function FindLabel ( [Address], [Building], [Unit] )
  If (IsNull([Unit])) And IsNull([Building])) Then
    FindLabel = [Address]
  ElseIf (Not(IsNull([Building])) And IsNull([Unit])) Then
    FindLabel = [Address] + vbNewLine + [Building]
  ElseIf (IsNull([Building]) And Not(IsNull([Unit]))) Then
    FindLabel = [Address] + vbNewLine + [Unit]
  End If
End Function

 

 

JosephPilkington1
New Contributor II

Argh! Lol. So frustrating! THANK YOU! It's a learning process for sure.

0 Kudos