-2

The code fails when run

What I try to do is to fill a field "CLASSNAME"(created text field) according to field "Value"'s value.

If the value in "Value"(raster's by default field) is 1, then in "CLASSNAME" is 1 or whatever, and so on if the value in "Value" is 2,3,4...etc.

I'm working on a raster's attribute table

I saw other questions and answers, none of them answers mine.

enter image description here

3
  • 2
    Please ask a question.
    – Vince
    Aug 23, 2018 at 2:13
  • 1
    Could you please expand on the question being asked? Does the script fail? What error does it give? Are your field set up correctly? Text and Numbers? Aug 23, 2018 at 2:24
  • 1
    Not sure about the elseif, you can simply use else. Other than that, as @Keagan Allan hinted at, make sure your field data types are correct. In your example, both [Value] and [val] are set up as Text. If this is not the case, try to convert them within the codeblock or set the fields up correctly. And by the way: similar question here: gis.stackexchange.com/questions/44008/…
    – s6hebern
    Aug 23, 2018 at 6:05

1 Answer 1

1

Your vba syntax is incorrect. An elseif requires you to specify the if part eg

If [Value] = '1' Then 
    val = '1'
ElseIf [Value] = '2' Then
    val = '2'
Else val = '3'
End If

If you're only wanting 1 or 2 then you need to use Else rather than ElseIf

If [Value] = '1' Then 
    val = '1'
Else val = '2'
End If

Additionally, if you are looking at numeric fields, you might want to remove the quote marks around the numbers

If [Value] = 1 Then 
    val = 1
Else val = 2
End If

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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