I have a couple of label expressions that I have used many times in ArcMap, but now trying to use them in Pro they no longer work and throw an error. I am using VBScript and have the Language set as such.
The code is pasted below. It basically goes through and finds a last name, first name and outputs the Last Name comma First letter of first name and first letter of third name from the first 3 words with the acreage (for example Jones, D. R.), that part works,
then it goes through and finds strings that don't have a comma (those are business names) and outputs the first full word period second word first letter period third word first letter period (for example Union Electric Company would be Union E. C.) The error is thrown from the code in bold at the bottom. The first part works but I have tried adding and taking away the other array strings from the split function and they are what is throwing the error. Again it has always worked fine in ArcMap!
The error is Invalid Expression Error 10 on line 0. Subscript out of range: '[number:1] :
Function FindLabel ( [OwnName1], [ACRES] )
Dim sWords
If IsNull ( [OwnName1] ) then
FindLabel="No Data"
else
If InStr( [OwnName1] ,",") <>0 then
sWords = Split( [OwnName1] , " ")
FindLabel = Left(sWords(0),12) & Left(sWords(1),1)& " " & Left(sWords(2),1) & ". " & Round( [ACRES] ,0)
else
sWords = Split( [OwnName1] , " ")
FindLabel = Left(sWords(0),12) & " " & Left(sWords(1),1)& "." & Left(sWords(2),1) & ". "& Round( [ACRES] ,0)
end if
end if
End Function
Thanks in advance for any insight you can give me~
MJ
I do believe VBScript is no longer supported in Pro. You will have to re-write your scripts into Python.
From the label documentation:
You can also use Arcade, Python, VBScript, or JScript in your label expression to change how the text is displayed.
You will have to throw a check in there to ensure that there are sufficient number of conditions in sWords.
I don't do vb but if sWords can be split and yields only 1 result the rest of that line will fail
This example adds to the string, no matter how many items are in sWords
Function FindLabel ( [D_STRUCT] )
Dim Label
Dim sWords
sWords = Split([D_STRUCT], " ")
For i = 0 To UBound(sWords)
If (i = 0) Then
Label = Left(sWords(i),12) & " "
Else
Label = Label + Left(sWords(i),1) & "."
End If
Next
FindLabel = Label
End Function
I have a ws script which is essentially vb script..I run for extracting data from cvs files which separates first last email ... you may find it helpful:
MyArray = Split(lineRead,",")
' MyArray(0) contains "FullName".
' MyArray(1) contains "spaces".
' MyArray(2) contains "email".
'set MyArray(1) to uppercase
Fullname = UCase(MyArray(0))
Email = (MyArray(2))
WScript.Echo Fullname & " " & Email
namearray = Split(Fullname," ")
testname = UBound(namearray)
If testname = "2" Then
Firstname = namearray(0)
Middlename = namearray(1)
Lastname = namearray(2)
ElseIf testname = "1" Then
Firstname = namearray(0)
Middlename = " "
Lastname = namearray(1)
Else
WScript.Echo "Name not right"
End If
WScript.Echo Firstname
WScript.Echo Middlename
WScript.Echo Lastname
So I have been working on getting this to work for days now, and I have looked at the examples here and tried to make them work with my example. I FINALLY got it working the way it should! The code probably isn't pretty. Anyway I thought I would post the result in case someone else needs it. The ReDim is what seemed to be the magic bullet! Thanks to everyone for your help...Still not sure why my original code works in ArcMap and not Pro but I guess it is more picky about getting clean code.
Function FindLabel ([OwnerName],[ACRES])
Dim sWords
Dim ownNm
ReDim sWords(3)
ownNm = [OwnerName]
If InStr(ownNm,", ") <>0 Then
sWords = Split(ownNm, " ")
FindLabel = Left(sWords(0),12) & " " & Left(sWords(1),1) & " . " & Left(sWords(2),1) & ". " & Round([ACRES],0)
Else
sWords = Split(ownNm, " ")
FindLabel = Left(sWords(0),12) & ". " & Left(sWords(1),1) & " . " & Round([ACRES],0)
End If
End Function