2

I realize this question has been asked in its basic form before, but I've tried a lot of code samples on answers posed to similar questions on this site to no avail.

I'd like to create a new field in my attribute table (Label) that uses the VBScript comparison operators in Field Calculator to define the value based on text values of a field within the table (STATUS).

If the field "STATUS" is "USFS", I want "Label" to equal "USFS".

If the field "STATUS" is not "USFS", I want the "Label" to equal "Other".

However, I always get a return value of "Other". Here is the pre-logic script code I'm using:

dim n

if [STATUS] = USFS Then

n = "USFS"

elseif [STATUS] <> USFS Then

n = "Other"

end if

See screenshots.

Attribute Table Field Calculator

5

While in your description you put quotes around USFS, you don't in your actual code

If the field "STATUS" is "USFS", I want "Label" to equal "USFS".

If the field "STATUS" is not "USFS", I want the "Label" to equal "Other".

USFS should be in double-quotes. The elseif fires every time because nothing equals USFS (without quotes) which is why they all return a value of "Other".

dim n
if [STATUS] = "USFS" Then
n = "USFS"
elseif [STATUS] <> "USFS" Then
n = "Other"
end if
  • 1
    You could make it simpler by setting all to "USFS" and then just check [STATUS] in an if statement. Or, use an else instead of elseif. – recurvata Feb 11 '16 at 21:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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