This label expression can be used to display long text strings from an attribute field as a multi-line label. Basically it attempts to add hard returns (line breaks) after every other word.
For example, the script will display the value "Western Washington County Special Service District 1, Pine Valley" as:
Western Washington County Special Service District 1, Pine Valley
There are three parameters to keep in mind.
The input field name, currently set to [Name] in the code below. Change this in two places to the field from which you would like to get the label string.
MaxWordLength, currently set to 10, change this to force long words onto their own line like 'Washington' in the example above
MixWordLength, currently set to 3, change this to keep short words from being put on the next line like '1,' in the example above
When using a label expression, you'll need to click the expression button on the label properties window and then click the advanced button. Delete the suggested code and replace it with the code below.
Function FindLabel ( [Name] )
Dim strArray Dim outStr Dim x Dim maxWordLength Dim minLengthLength Dim everyother Dim isFirst Dim lastWordLong lastWordLong = false
If ((Not isFirst) And (Len(strArray(x)) <= minWordLength)) Then 'keep short word on existing line outStr = outStr & " " & strArray(x) everyother = False ElseIf (everyother) Then 'word x is slated to be second word on line If (Len(strArray(x)) > maxWordLength) Then outStr = outStr & vbNewLine & strArray(x) everyother = False Else outStr = outStr & " " & strArray(x) everyother = False End If Else 'word x is slated to be first word on line If (isFirst) Then outStr = strArray(x) everyother = True isFirst = False Else If (Len(strArray(x)) > maxWordLength) Then lastWordLong = True everyother = False Else lastWordLong = False everyother = True End If