I have an expression in VBscript that works well for labeling:
Function FindLabel (field)
if (INT(RIGHT(field, 2)) <> 1) then
FindLabel = INT(MID(field, 8, 3)) &"-"& INT(RIGHT(field,2))
else
FindLabel = INT(MID(field, 8, 3))
end if
End Function
This expression labels a text in this format: VCC065-00102 to: 1-2 or from VCC065-00501 to: 5 (using just the last 5 carachters, if the last one is > 1, it shows the number after a "-").
But, when I tried to use the same script for calculating a field, I've got a syntax error error:
Code block: the same as above
Expression:
FindLabel ([DATA])
Also, I tried to convert this script to Python:
Code Block:
def FindLabel (Field):
Var1 = Field[-2:]
Var2 = Field[8:-3]
if (int(Var1) <> 1 ):
FindLabel = int(Var2) &"-"& int(Var1)
else:
FindLabel = int(Var2)
Expression:
FindLabel (!DATA!)
But it returns an error: The field is not nullable. (I don't know why, but the expression is returning a null value)
Thanks!