Select to view content in your preferred language

Adding onto an Elseif statement in label expression for ArcMap 10.5

1602
2
03-08-2019 07:44 AM
AriLukas
Regular Contributor

I am admittedly a novice when it comes to coding but I have written a fairly simple Elseif VBscript in the the Label Expression in ArcMap 10.5. The expression shown below is for Overhead Conductors and currently will display a label based on what phase is input into the Conductor fields (ConductorA, ConductorB, ConductorC, ConductorN ).

I am trying to add onto this expression.

I have a field called Construction Status which contains coded values (Installed, Proposed, Other). I would like the labels for my Overhead Conductors to become bold and a larger font when the Construction Status field says Proposed.

I have tried some basic HTML coding but I keep receiving error messages when trying to verify and am currently at a lose with the little coding experience I have.

Function FindLabel ( [conductora], [conductorb], [conductorc], [conductorn] )
dim a
if [conductora] <> "" and [conductora] <> "NA" then
a = a & [conductora]
elseif [conductorb] <> "" and [conductorb] <> "NA" then
a = a & [conductorb]
elseif [conductorc] <> "" and [conductorc] <> "NA"then
a = a & [conductorc]
elseif [conductorn] <> ""and [conductorn] <> "NA" then
a = a & [conductorn]
end if
FindLabel = a
End Function

Tags (1)
0 Kudos
2 Replies
JimCousins
MVP Alum

From the Help under Layer>>Labels>>Expression:

Building label expressions

  • Function FindLabel ([NAME], [POPULATION])   if (cLng([POPULATION]) >= 250000) then    FindLabel = "<CLR red='255'><FNT size = '14'>" + [NAME] + "</FNT></CLR>"   else 	 FindLabel = [NAME]   end if End Function
    You will need to modify the fields/variables to match your needs.
    The formatting tag for bold is <BOL> followed by </BOL>
    This information is available under "Using Formatting Tags" in the help.
    
    Best Regards,
    Jim
0 Kudos
rachelg_esri
Esri Contributor

Hello Ari,

While I'm a bit rusty with VBScript, I'm familiar with Python enough to be able to fiddle around with if statements. I'm not sure if this is exactly what you were aiming for, but you may be able to modify this a bit to suit your needs. You'd have to choose the Python parser and check Advanced for it to work:

def FindLabel ( [conductora], [conductorb], [conductorc], [conductorn]):
    a=""
    if str([conductora]) not in ["None","NA"]:
        a=a+"A"+str([conductora])
    if str([conductorb]) not in ["None","NA"]:
        a=a+"B"+str([conductorb])
    if str([conductorc]) not in ["None","NA"]:
        a=a+"C"+str([conductorc])
    if str([conductorn]) not in ["None","NA"]:
        a=a+"N"+str([conductorn])
    return a

Here's an image of the final results:

Hopefully that, plus some formatting, gets you what you need.

Another thought is to use Label Classes to modify expressions based on subsets of your data. Then you won't have to deal with the if/else logic.

Using label classes to label features from the same layer differently—Help | ArcGIS Desktop 

If you need clarification, let us know!

Best regards,

Rachel

Esri Support Services

Rachel Guttmacher
ArcGIS Online Technology Lead
Esri Support Services
0 Kudos