Label Expression

2962
9
Jump to solution
01-19-2012 07:12 AM
CaraMays
New Contributor
I am needing to label a map with owner names but I would like to trim the name to one character after a comma. I also have owner names that are not divided by a comma so I would like to trim them to a 13 characters. I am having trouble writing the expression for this. Any help would be great.
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RichardFairhurst
MVP Honored Contributor
This is what we have used in the past. But I either get "Carriage reurns are not allowed in simple expressions" or "This expression contains an error".

Function FindLabel ( [PartyName]  )
  Owner = [PartyName] 
  if InStr ( 1 , Owner , "," ) > 1 then
    MyPos = InStr ( 1 , Owner , "," )
    DisplayChars =  Left ( Owner , MyPos + 2 )
    FindLabel = DisplayChars
  else
    FindLabel = Left ( Owner , 13 )
  end if
End Function


You must check the box for an Advanced Label expression to use either your code or my code.

View solution in original post

0 Kudos
9 Replies
RichardFairhurst
MVP Honored Contributor
I am needing to label a map with owner names but I would like to trim the name to one character after a comma. I also have owner names that are not divided by a comma so I would like to trim them to a 13 characters. I am having trouble writing the expression for this. Any help would be great.


What are the field names involved?  Do all of the names have to fit in 13 characters?  Actual examples of names that are too long in each format and how you want them to be labeled would help for developing the VB Script code.  Most likely you will use the Split or InStr functions, but that is as far as I can say with the information you have given.
0 Kudos
CaraMays
New Contributor
The name of the attribute I am wanting to trim is [PartyName]. Example of how I want the name trimmed after a comma would be Huebner, Melvin and I would just like the label name to say Huebner, M. Names without commas such as Huebner Family Trust I would like short enough to fit within in my parcel and we have used 13 characters before. Does this give enough information?

Thank you for your time.
0 Kudos
RichardFairhurst
MVP Honored Contributor
Try the code below in the Label Expression field:

Function FindLabel ( [PartyName] )
if InStr( [PartyName] , ",") > 0 Then
  myArray = Split( [PartyName] , ",")
  FindLabel = myArray(0) & ", " & LEFT(Trim(myArray(1)), 1) & "."
ElseIf Len( [PartyName] ) > 13 Then
  FindLabel = Left([PartyName], 13)
Else
  FindLabel = [PartyName]
End If
End Function
0 Kudos
CaraMays
New Contributor
This is what we have used in the past. But I either get "Carriage reurns are not allowed in simple expressions" or "This expression contains an error".

Function FindLabel ( [PartyName]  )
  Owner = [PartyName] 
  if InStr ( 1 , Owner , "," ) > 1 then
    MyPos = InStr ( 1 , Owner , "," )
    DisplayChars =  Left ( Owner , MyPos + 2 )
    FindLabel = DisplayChars
  else
    FindLabel = Left ( Owner , 13 )
  end if
End Function
0 Kudos
RichardFairhurst
MVP Honored Contributor
This is what we have used in the past. But I either get "Carriage reurns are not allowed in simple expressions" or "This expression contains an error".

Function FindLabel ( [PartyName]  )
  Owner = [PartyName] 
  if InStr ( 1 , Owner , "," ) > 1 then
    MyPos = InStr ( 1 , Owner , "," )
    DisplayChars =  Left ( Owner , MyPos + 2 )
    FindLabel = DisplayChars
  else
    FindLabel = Left ( Owner , 13 )
  end if
End Function


You must check the box for an Advanced Label expression to use either your code or my code.
0 Kudos
CaraMays
New Contributor
It worked! Thank you so much for your help!!! It is very much appreciated!
0 Kudos
RichardFairhurst
MVP Honored Contributor
It worked! Thank you so much for your help!!! It is very much appreciated!


Please click on the checkmark under the rating number to mark this thread as answered so that the thread will appear to everyone as closed and for the benefit of others.
0 Kudos
DanHaasken
New Contributor II
Thanks! This helped me greatly when trying to create a county plat book. One other thing I'm trying to do is use the name field, (TAO_NAME), and include the first initials of the owner's first names. For example I want "Doe, John & Mary" to appear on my map as "Doe, J & M" Or, I would really like to create a label expression that would label the first names first and the last name last. Both first and last names are currently all in the same field. So, for the above example, I'd like it to appear on my map as "John & Mary Doe" or "J & M Doe" with no commas. Any help would be appreciated.

Thanks,
Dan
0 Kudos
ChristopherBlinn1
Occasional Contributor III
Daniel,

If all of your names have the "LastName, FirstName1 & FirstName2" syntax, you could create an array of the value, splitting each value by space:

myArray = Split(TAO_NAME, " ")

Then having all of your elements in the array, just rearrange them and use only the characters you need:

Left(myArray(1), 1) & " & " & Left(myArray(3), 1) & " " & Left(myArray(0),(Len(myArray(0)) - 1))

I have not tested this code, so it is quite possible I forgot a paranthesis or comma here or there.

Hope this helps!

Best,
Chris B.
0 Kudos