Field Calculator VB Script

6935
13
03-31-2016 08:03 AM
AzaN
by
New Contributor III

Hi All.

I am trying to calculating a field ([Status]) based on another field ([SymbolID]). The code that I am using is as below:

Dim Status

IF [SymbolID] = '0' THEN

Status = 'In Construction'

Else

Status =  'Planned'

EndIf

But I keep receiving failure messages. Could you please help me with that?

Thanks in advance,

Aza

0 Kudos
13 Replies
ChristopherThomas
New Contributor III

VB script requires double quotes.

Try:

Dim Status

IF [SymbolID] = "0" THEN

Status = "In Construction"

Else

Status =  "Planned"

End If

AzaN
by
New Contributor III

Thanks. I tried , but still gives the same message.

0 Kudos
ChristopherThomas
New Contributor III

Also, I noticed your original EndIf needs a space in it: End If

I tested it here with a file geodatabase and a sql server feature class and it worked for me. What version of ArcGIS are you using?

0 Kudos
AzaN
by
New Contributor III

I wonder why it doesn't work for me. I also tried different types of field (Double, Text, etc.). I work with Arc GIS 10.1.

0 Kudos
DarrenWiens2
MVP Honored Contributor

Since you're returning text, your field must be text.

Remove the "Dim..." line. Dim is for VBA, not VBScript.

AzaN
by
New Contributor III

Thanks. I have also tried so, but didn't work either.

0 Kudos
ChristopherThomas
New Contributor III

Here is a screenshot of what worked for me using the Calculate geoprocessing Tool in 10.3.1...

In this case SymbolID is a text field and Status is a text field length of 50 that I added to my Zoning feature class.

If you have not already, try restarting ArcGIS to make sure nothing is locked or old variables get cleared from memory.

AzaN
by
New Contributor III

Thanks again, Christopher. I followed all the steps you mentioned. Also restarted ArcGIS, but unfortunately didn't work again. Here is a screen shot:

0 Kudos
ChristopherThomas
New Contributor III

Aza, what Joshua Bixby said below... you only need to put the variable name "Status" into the expression. Post what the error message is if you still do not get that to work.

0 Kudos