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
-
Could you tell us what you have tried yourself?Berend– Berend2016年01月12日 10:20:46 +00:00Commented Jan 12, 2016 at 10:20
-
5Maybe 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).Berend– Berend2016年01月12日 11:08:35 +00:00Commented 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...Hornbydd– Hornbydd2016年01月12日 11:30:30 +00:00Commented 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.Berend– Berend2016年01月12日 11:56:32 +00:00Commented 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.Nature_girl– Nature_girl2016年01月12日 11:58:40 +00:00Commented Jan 12, 2016 at 11:58
1 Answer 1
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
Explore related questions
See similar questions with these tags.