4

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

  • 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. – Michael Stimson Jun 2 '15 at 1:52
4

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
0

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

if ( [Label] = 1) then

 FindLabel =( [NAME])

end if

End Function

VB parser

  • 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 Jun 25 at 19:37

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.