Select to view content in your preferred language

ArcMap VBScript

818
2
12-24-2018 08:25 AM
ShaningYu
Honored Contributor

I need to display Label w/ 2 fields' values like that  [_PID] & "/" & [_NAME].  Its VBScript looks like that below:

[_PID] & "/" & [_NAME]

But if [_PID] == [_NAME], I only need to display [_PID].  I tried the VBScript below:

Function FindLabel ( [_PID] )
 dim newString as string
 newString = ""
 if [_PID] == [_NAME]  then
  newString = [_PID]
else
  newString = [_PID] & "/" & [_NAME]
end if

However, I receive error: "Carriage returns are not allowed in simple expressions".

How this problem can be fixed?  Thanks if you can help.

Tags (1)
0 Kudos
2 Replies
ShaningYu
Honored Contributor

Changed to

Function FindLabel ( [_PID], [_NAME] )
if [_PID] <> [_NAME] then
FindLabel =  [_PID] & "/" & [_NAME]
else
FindLabel =  [_PID]
end if
end function

Then it works.  Thanks for your review.

0 Kudos
KenBuja
MVP Esteemed Contributor

In VBScript, you'll always get an error if you instantiate a variable as a specific object like this:

dim newString as string

You have to just do that like this:

dim newString 
0 Kudos