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!
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
-
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– dubhousing2012年11月13日 21:20:55 +00:00Commented Nov 13, 2012 at 21:20
-
Can you show a screen shot of the attribute table?kenbuja– kenbuja2012年11月13日 21:36:55 +00:00Commented Nov 13, 2012 at 21:36
-
Sure! It's here: i.imgur.com/GkR6W.png Thanks for your help!dubhousing– dubhousing2012年11月14日 01:23:23 +00:00Commented Nov 14, 2012 at 1:23
-
I've run it again using joined data like you have and it still runs properly. See the above imagekenbuja– kenbuja2012年11月14日 14:42:42 +00:00Commented Nov 14, 2012 at 14:42