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 want to write an if then in field calculator that tests if a field in the attribute table contains one of several versions of another string (the versions vary by capitalization).

Trouble is, I can't get even a simple if then to work, let alone an if then else if, which i would need here. I'm getting a 9999 error when I try the following:

(in the pre-logic script code)

Dim onlorain as Long
If InStr( [Export_Output.std],"Lorain" )>0 Then
onlorain = 1
else onlorain = 0
end if

(in the variable = ('parcel.onlorain =') box)

onlorain

I've posted a screenshot here:

screenshot

I'd thought that ultimately, I'd be striving (when I build in the capitalization variants) for something like

Dim onlorain as Long
If InStr( [Export_Output.std],"Lorain" )>0 Then
onlorain = 1
elseif InStr( [Export_Output.std],"LORAIN" )>0 tHEN
onlorain = 1
elseif InStr( [Export_Output.std],"lorain" )>0 tHEN
onlorain = 1
else
onlorain = 0
end if

But if the 'simple', 1st version of this won't work, this won't work either.

Hope someone has thoughts.

Thanks in advance!

share|improve this question
add comment

1 Answer 1

Here's a solution that should work. It also uses the UCase function that will convert your text to uppercase, so you don't have to check for all variants

dim output
if InStr(UCase( [Export_Output.std]), "LORAIN") > 0 then
  output = 1
else
  output = 0
end if

You'll also put "output" into the lower box

EDIT

Here's another test using joined data like in your original case.

enter image description here

share|improve this answer
    
Hmm ... tried this version, and in this case, the geoprocessing doesn't fail, but it doesn't seem to assign values correctly; none of the records that should take a '1' are receiving them. –  dubhousing Nov 13 '12 at 21:20
    
Can you show a screen shot of the attribute table? –  kenbuja Nov 13 '12 at 21:36
    
Sure! It's here: i.imgur.com/GkR6W.png Thanks for your help! –  dubhousing Nov 14 '12 at 1:23
    
I've run it again using joined data like you have and it still runs properly. See the above image –  kenbuja Nov 14 '12 at 14:42
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.