[GIS] If-Then Label Expression

arcgis-desktopexpressionif statementlabelingvbscript

I'm trying to create a VB label expression on streets such that streets with an alternate name (ACS_ALIAS) will be labeled with the LABEL name and the alternate name in parentheses; streets with no alternate name will be labeled with the LABEL name only. Here is what I tried but to no avail:

Function FindLabel ( [LABEL], [ACS_ALIAS] )

if ( [ACS_ALIAS] <> <Null> ) then

FindLabel = ( [LABEL] & " (" & [ACS_ALIAS] & ")" )

elseif ( [ACS_ALIAS] = <Null> ) then

FindLabel = [LABEL]

end if

End Function

I can only think of some non-expression workarounds.

enter image description here

Best Answer

Your conditional statements are not correct. If you simply want to include a field in a label if it contains a value, then you can check if the field is null or blank. If so, then just use [LABEL], if not, then label both fields as you mentioned.

Function FindLabel ( [LABEL], [ACS_ALIAS] )
    if IsNull([ACS_ALIAS]) OR Trim([ACS_ALIAS]) = "" then
        FindLabel = [LABEL]
    else
        FindLabel = [LABEL] & " (" & [ACS_ALIAS] & ")"
    end if
End Function
Related Question