I have a Field in this table which reads, and this is a sample because there are over 82,000 tracks in this county, "40 acres".

enter image description here

I do have this Script which I know took the "Acres" portion out of the field and the number portion is the only part of the field I need, and this looks like this.

enter image description here

This is the way I have entered this Script:

enter image description here

But I keep getting this error message:

enter image description here

What am I doing wrong?

  • 2
    Could you edit the question and add the code as text? Change parser from VB Script to Python. You call the function with formatAcres(!RECRDAREATX!) which is python, formatAcres([RECRDAREATX]) is VB – BERA Jun 21 '18 at 16:13
  • Looks like the fields are different names (!RECRDAREATX!) opposed to (!RECRDAREAT!) also. – cm1 Jun 21 '18 at 16:19
  • @Moh's answer below is correct. That code you have is Python code, not VBscript, so you need to select the radio button for Python. However, Moh also noted some other slight errors you should check on as well. – alexGIS Jun 21 '18 at 16:21

You should use this code in Python:



Just click on Field calculator >> Parsing (python) >>Show code block

Pre-logic script

def formatAcres(acrestring):
 formatString=acrestring.split(' ')
 if formatString[0] != None:
  return float(formatString[0])
  return None


formatAcres( !RECRDAREAT! )

Even simpler, if Acres is always the word to delete

  • int(!Field!.upper().replace('ACRES','')) would work better, it's not dependent on a fixed length string and can be modified easily like int(!Field!.upper().replace('ACRES','').replace('AC','')) to eliminate any other unit abbreviations. This will also work if the field is '40acres' or '40 Acres'.. if the field you're calculating is a string you might need to str(int(....)) to get the numeric value into a string field. – Michael Stimson Jun 21 '18 at 23:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.