Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm trying to run a rather lengthy model (built in ArcGIS 9.3.1) in ArcGIS 10.1 and I'm recieving an error on a Calculate Field tool. The error is - Type mismatch: 'iif'.

This error is refering to an expression in the tool: iif(IsNull( [PID] ) ,NA,[PID]).

enter image description here

I tried "if" instead of "iif" but then recieved a generic error.

I never had this issue when running the model in 9.3.1. I'm not sure what to do here. Any suggestions?

share|improve this question
2  
did you try quoting NA? –  Kirk Kuykendall Mar 1 '13 at 18:50
add comment

2 Answers

up vote 3 down vote accepted

You can't use iif directly in field calculator expressions, you need to use the code block. There are some examples on the Field Calculator Examples help page.

Python:

Expression:
Reclass(!WELL_YIELD!)

Expression Type:
PYTHON_9.3

Code Block:
def Reclass(WellYield):
    if (WellYield >= 0 and WellYield <= 10):
        return 1
    elif (WellYield > 10 and WellYield <= 20):
        return 2
    elif (WellYield > 20 and WellYield <= 30):
        return 3
    elif (WellYield > 30):
        return 4

VBA:

Expression:
density

Expression Type:
VB

Code Block:
Dim density
If [POP90_SQMI] < 100 Then
density = "low"

elseif [POP90_SQMI] < 300 Then
density = "medium"

else
density = "high"
end if
share|improve this answer
1  
That would be VBScript, not VBA. VBA was removed from the Field Calculator at 10. IIF is a VBA function. The reason it's not working at 10.1 is that it doesn't exist in VBScript. Otherwise this is a good answer. –  blah238 Mar 1 '13 at 18:55
    
Thank's guys. For dummies like me, how would you go about writing the code block. Sorry for being such a vampire, I don't know much about coding. –  dchaboya Mar 1 '13 at 19:05
    
This worked, thanks dmahr. And thanks to nmpeterson for spoon feeding me the code block. –  dchaboya Mar 5 '13 at 17:30
add comment

As dmahr said, you have to use a codeblock. In your case, that would be something like this, using Python:

def null_to_NA(field):
    if field == None:
        return 'NA'
    else:
        return field

And then the expression would be:

null_to_NA(!PID!)
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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