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 am trying to use ArcMap's Field Calculator to populate values in a column based on a value in another column. So, in pseudo-code:

if [field1] = 'Foo'
  set [field2] = 'Bar'
endif

Something like that. Test for 'foo' in the first attribute, and set the record's second attribute to 'bar.' Seems like it should be pretty easy to do, but I keep receiving a "user interrupt" error every time I try running anything. I think I have a misunderstanding of how to build VBA expressions with the Field Calculator...

share|improve this question
    
What version of arcmap? I think VBA in the field calculator got deprecated at 10.0. Here's a good intro to the python calculator. –  Kirk Kuykendall Mar 1 '11 at 14:50
add comment

1 Answer 1

up vote 12 down vote accepted

Try something like this:

dim f2
if [field1] = "foo" then
  f2 = "bar"
end if

Screen shot of this being used in the field calculator.alt text

share|improve this answer
    
Works like a charm. Thanks! –  colemanm Sep 15 '10 at 19:49
    
I totally LOVE this forum! I would have spent 3 days on Esri's forums looking for this answer and found it in 2 minutes here! Thanks! Woot Woot!!! - i.imgur.com/Pe6fb.jpg –  sirgeo Mar 1 '11 at 14:32
    
This works great but I was trying to nest 'if' statements and can't. So if [grid_code] = 1 then f2= 2 end if if[grid_code] = 2 then f2=3.5 end if...etc. but this doesn't work? what am I doing wrong. I tried it before the end if and also tried elif. Also any idea why I get a warning message about field 1 being null and have to click yes to continue? –  GeorgeC Oct 26 '11 at 10:22
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.