2

I have a file with an attribute table with data in 3 columns, and would like to use field calculator to populate a 4th column. The data is integer numbers between 0 and 56. I want the new column to tell if the numbers in the 3 previous columns are identical or not. I would like the 4th column to state "3" if all 3 columns have the same number, "2" if 2 are the same, and "0" if none of the columns contain the same number.

Does anyone know how to do this calculation?

I tried the following in VB script, but I still get an error message: enter image description here

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Jan 12, 2016 at 10:07
6
  • Could you tell us what you have tried yourself? Commented Jan 12, 2016 at 10:20
  • 5
    Maybe you could add that code snippet to your original question. Not everyone reads all comments when answering. If you do, indent the code with 4 spaces, so it will be formatted as code (see my answer below). Commented Jan 12, 2016 at 11:08
  • @Nature_girl move your comment into your question then delete the comment, as it stands its unreadable! If you want people to help you, you need to create easy to understand questions not dense blocks of text... Commented Jan 12, 2016 at 11:30
  • Erm wait, originally this question was about VBScript. You now modified it to Python. Please don't do that, as it may make answers obsolete. Instead, you could post a new question which references this one. Commented Jan 12, 2016 at 11:56
  • Thanks for your help - as you understand I'm totally new to this. Changed it back to VBScript now using your suggested code. Commented Jan 12, 2016 at 11:58

1 Answer 1

5

VBScript does not support syntax such as a=b=c to compare three values. Instead, you should write something like a=b AND a=c.

The complete pre-logic block could be

If [Grunntype] = [Grunntyp_1] And [Grunntype] = [Grunntyp_2] Then 
 Lik_grtyp = 3 
ElseIf [Grunntype] <> [Grunntyp_1] And [Grunntype] <> [Grunntyp_2] And [Grunntyp_1] <> [Grunntyp_2] Then 
 Lik_grtyp = 0
Else 
 Lik_grtyp = 2
End If
answered Jan 12, 2016 at 11:05
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.