5

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

1
  • The function that you want to use to test if a value is <NULL> is IsNull msdn.microsoft.com/en-us/library/office/gg278616.aspx.. elseif ( isnull([ACS_ALIAS])) then apart from that I don't see much wrong with it. IsNull only works with databases that support NULL (not shapefile) but you must be aware that empty strings are not NULL so the test has to be IsNull(field) then len(field)=0, if you go straight for len(field) it can fail if the value is NULL with an error message. Commented Jun 2, 2015 at 1:52

3 Answers 3

5

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
2
Function FindLabel ( [NAME], [Label]  )

if ( [Label] = 1) then

 FindLabel =( [NAME])

end if

End Function

VB parser

1
  • Welcome to GIS SE. As a new user, please take the Tour. Please Edit your answer to provide some more words (non-code) to describe your recommended solution. Note that three backquotes will start/stop a code block, as will indenting four spaces.
    – Vince
    Commented Jun 25, 2019 at 19:37
1

You need the second part of your argument in the If statements. You've got the field name and then an operator, but no value. [ACS_ALIAS] <> "" or [ACS_ALIAS] = "Something"

Without a value to compare the field value to the computer doesn't know what to compare to.

Like this:

Function FindLabel ( [LABEL], [ACS_ALIAS] )

if ( [ACS_ALIAS] <> **VALUE HERE**) then
FindLabel = ( [LABEL] & " (" & [ACS_ALIAS] & ")" )

elseif ( [ACS_ALIAS] = **VALUE HERE**) then

FindLabel = [LABEL]
end if

End Function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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