Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm starting to work with the advanced findlabel function in ArcMap label expression editor. I will say I'm a complete novice at this up front. Here is what I have so far:

Function FindLabel ( [SwineWeFin] , [SwineGrFin] , [SwineNurse] , [SwineGesBo] , [SwineSowLt] , [SwineGilti] , [CattleDaHl] , [CattleDaJr] , [CattleDaHf] , [CattleBeFn] , [CattleBeFe] , [CattleVeal] , [TurkeyFin] , [TurkeyPlBr] , [ChickenLBr] , [ChickenPul]     )

 if ( [SwineWeFin]  > 0) then  FindLabel = [SwineWeFin] & " WTM "   

 if ( [SwineGrFin] > 0) then  FindLabel = [SwineGrFin] & " FTM"   

 if ( [SwineNurse]  > 0) then  FindLabel = [SwineNurse] & "Nursery"  

 if ( [SwineGesBo] + [SwineSowLt]  > 0) then  FindLabel = [SwineGesBo] + [SwineSowLt]  & "Sows"  

 if ( [SwineGilti]  > 0) then  FindLabel = [SwineGilti]  & " Gilts"   

 if ( [CattleDaHl] +  [CattleDaJr] +  [CattleDaHf] +  [CattleBeFn] +  [CattleBeFe] +  [CattleVeal]  > 0) then FindLabel = "Cows"

 if ( [TurkeyFin] + [TurkeyPlBr]  > 0) then  FindLabel =  "Turkey"

 if ( [ChickenLBr] + [ChickenPul]  > 0) then  FindLabel = "Chickens"

End Function

This mess actually works for me. The problem that I have is when two or more of the "if' criteria apply to the same point. Currently, the label will only show the first criteria that is found to be true. I want all criteria that are true to be shown as a label. I would prefer if it showed each TRUE item on a new line for the label.

Is what I'm wanting to do even possible? And if so, how would I script it? Thanks!!!!

share|improve this question
    
You might also consider redesigning your database so that all this logic is not needed. –  blah238 Jan 14 '13 at 19:57
add comment

1 Answer 1

up vote 4 down vote accepted

What you'll want to do is something like this.

Function FindLabel ( [SwineWeFin] , [SwineGrFin] , [SwineNurse] , [SwineGesBo] , [SwineSowLt] , [SwineGilti] , [CattleDaHl] , [CattleDaJr] , [CattleDaHf] , [CattleBeFn] , [CattleBeFe] , [CattleVeal] , [TurkeyFin] , [TurkeyPlBr] , [ChickenLBr] , [ChickenPul] )

    if ( [SwineWeFin] > 0) then output = [SwineWeFin] & " WTM "
    if len(output) > 0 then output = output & vbNewLine
    if ( [SwineGrFin] > 0) then output = output & [SwineGrFin] & " FTM"
    if len(output) > 0 then output = output & vbNewLine
    if ( [SwineNurse] > 0) then output = output & vbNewLine & [SwineNurse] & "Nursery"
    if len(output) > 0 then output = output & vbNewLine
    if ( [SwineGesBo] + [SwineSowLt] > 0) then output = output & vbNewLine & [SwineGesBo] + [SwineSowLt] & "Sows"
    if len(output) > 0 then output = output & vbNewLine
    if ( [SwineGilti] > 0) then output = output & vbNewLine & [SwineGilti] & " Gilts"
    if len(output) > 0 then output = output & vbNewLine
    if ( [CattleDaHl] + [CattleDaJr] + [CattleDaHf] + [CattleBeFn] + [CattleBeFe] + [CattleVeal] > 0) then output = output & vbNewLine & "Cows"
    if len(output) > 0 then output = output & vbNewLine
    if ( [TurkeyFin] + [TurkeyPlBr] > 0) then output = output & vbNewLine & "Turkey"
    if len(output) > 0 then output = output & vbNewLine
    if ( [ChickenLBr] + [ChickenPul] > 0) then output = output & vbNewLine & "Chickens"

    FindLabel = output

End Function
share|improve this answer
    
Thanks! That works perfect for what I'm trying to do. –  Seth_ia Jan 14 '13 at 19:33
    
Great...don't forget to mark this as the answer. –  kenbuja Jan 14 '13 at 19:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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