3

I am trying to label a field based on other field.

For 
[TYPE] = "PRIMARY", the [LABEL] is having this structure: "TAN80901B"
For 
[TYPE] = "SECONDARY", the [LABEL] is like this: "TAN80901C/D20b"

I want the [LABEL] to return "B" if "PRIMARY" and "D20" if "SECONDARY"

To delete from the right and left, I can use : "left(right( [LABEL], 5), 2)"

Any help with this expression?

2

If i follow you correctly, you can do this in vbs without using the left/right

Dim Result
if [TYPE] = "PRIMARY" 
   then Result = "B"
elseif [TYPE] = "SECONDARY" 
   then Result = "D20"
End If 

[LABEL] = Result


with the new information (and how i understand your question) i think this will work (I am not at the office nor do I have Arc handy to test) :

Dim Result
    if [TYPE] = "PRIMARY" 
       then Result = Right([LABEL],1)
    elseif [TYPE] = "SECONDARY" 
       then Result = Right([LABEL],3)
    End If 

[LABEL] = Result

  • Thanks! I need left/right because [LABEL] is having unique characters: TAN80901A, TAN80901B, TAN80901C, TAN80901C/D05b, TAN80901C/D10b, TAN80901C/D20b... – Fflavioo Jan 26 '16 at 12:50
  • I dont follow, could you give a little bit better pseudocode/logic I bet I can figure it out though. Or maybe you can show a screenshot of your table and exactly what you are doing. – ed.hank Jan 26 '16 at 12:52
  • I am not sure if I can paste a image here. – Fflavioo Jan 26 '16 at 13:01
  • However, the field "TYPE" has 2 values: PRIMARY and SECONDARY and the field "LABEL" has 3 unique values for PRIMARY and hundred of values when SECONDARY: TAN80901A, TAN80901B and TAN80901C (for TYPE = PRIMARY) and TAN80901C/D05b, TAN80901C/D10b, TAN80901C/D20b, TAN80901C/D19b...etc (for TYPE = SECONDARY). I need to extract "A", "B" and "C", if TYPE is PRIMARY (ex: TAN80901A) and D01-D20 if TYPE is SECONDARY (ex: TAN80901C/D20b). – Fflavioo Jan 26 '16 at 13:09
2

If you switch the parser to Python, and desired Secondary values are always the same length and position (e.g., Secondary is always the last 4 characters), you could do this:

def FindLabel([PRIMARY], [SECONDARY]):
    primType = [PRIMARY].upper()
    second = [SECONDARY].upper()
    if primType == 'PRIMARY':
        return second[-1]  # last character of SECONDARY
    elif primType == 'SECONDARY':
        return second[-4:-1]  # characters 4th from last to 2nd from last of SECONDARY
    else:
        pass # in case of Null/empty values

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.