4

I want to assign numbers to a certain types of building and I need to use field calculator. I tried many different versions of this and I still can't find what's wrong. Could you tell me where do I make a mistake?

![Printscreen]1

  • obyv column is a short type... I tried float (among others) but didnt help. – Robert Spal Oct 27 '15 at 12:09
  • 9
    Looks like a script for VB instead of Python, perhaps check the parser for VB Script? – Joseph Oct 27 '15 at 12:12
  • Artwork 21 has answered this but just for your info (and sanity) write your field calculator expressions in a text editor that supports python syntax highlighting. Notepad++ or similar. It will greatly decrease frustration - the field calculator is such an unfriendly tool. – kingmi Nov 4 '15 at 11:24
  • Yep, I just found out how unfriendly it is. I will use notepad next time. Thanks – Robert Spal Nov 5 '15 at 11:52
7

Your python syntax is not correct, try:

def myFunc(typ, oby):
  if typ == 'D':
    return 'Z'
  else: return '25'

function call:

myFunc(!TYP!, !obyy!)
2

Here is a working if/then statement in VBS.

For your code, I would think something like this:

Dim result
if [TYP] = "D" then
     result = "Z"
else result = "25"
end if

And:

obyv = result
0

Looks like you used "=" rather than "==".

def countRows(rowcount): 
    import arcpy 
    if %rowcount% == 0: 
        return "false" 
    else: 
        return "true"
  • There is no need to import arcpy and I think doing so would make this run very slowly. – PolyGeo Nov 4 '15 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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