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

nmtoken
13.6k5 gold badges39 silver badges91 bronze badges
asked Oct 27, 2015 at 12:07
4
  • obyv column is a short type... I tried float (among others) but didnt help. Commented Oct 27, 2015 at 12:09
  • 9
    Looks like a script for VB instead of Python, perhaps check the parser for VB Script? Commented Oct 27, 2015 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. Commented Nov 4, 2015 at 11:24
  • Yep, I just found out how unfriendly it is. I will use notepad next time. Thanks Commented Nov 5, 2015 at 11:52

3 Answers 3

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!)
answered Oct 27, 2015 at 12:14
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
answered Oct 27, 2015 at 12:13
0

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

def countRows(rowcount): 
 import arcpy 
 if %rowcount% == 0: 
 return "false" 
 else: 
 return "true"
PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
answered Oct 27, 2015 at 17:55
1
  • There is no need to import arcpy and I think doing so would make this run very slowly. Commented Nov 4, 2015 at 10:50

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.