If conditional Expression

850
5
Jump to solution
03-20-2017 08:14 AM
CarlosPires2
New Contributor

I need to fill a field using an expression, but including a condition.

I have two fields:

GRIDCODE (field reference, unique values from 0 to 2"

ERRO - blank field I would fill as follow:

If GRIDCODE value is 0, then ERRO value is: "Não há diferença"

If GRIDCODE value is 1, then ERRO value is: "Área de uso consolidado cadastrada como nativa"

If GRIDCODE value is 2, then ERRO value is: "Área de vegetação nativa cadastrada como uso consolidado"

I tried use this expression, but it doens´t work.. looks like it has a sintaxe error.

If [GRIDCODE] = 0 Then
[Erro] = "Não há diferença"
ELSEIF [GRIDCODE] = 1 Then
[Erro] = "Área de uso consolidado cadastrada como nativa"
ELSEIF [GRIDCODE] = 2 Then
[Erro] = "Área de vegetação nativa cadastrada como uso consolidado"


End If

Thank you very much!

0 Kudos
1 Solution

Accepted Solutions
EdwinRoa
Esri Contributor

Hi 

I'm agree with Daren.  You need to store the result in a variable. 

Dim value
If [GRIDCODE] = 0 Then
value = "Não há diferença"
ELSEIF [GRIDCODE] = 1 Then
value = "Área de uso consolidado cadastrada como nativa"
ELSEIF [GRIDCODE] = 2 Then
value = "Área de vegetação nativa cadastrada como uso consolidado"

End If

And put into a calculator. 

View solution in original post

0 Kudos
5 Replies
DarrenWiens2
MVP Honored Contributor

You need to store the value in a variable, and use that variable name as the expression:

Expression:

result‍

Code block:

If [GRIDCODE] = 0 Then
result = "Não há diferença"
ELSEIF [GRIDCODE] = 1 Then
result = "Área de uso consolidado cadastrada como nativa"
ELSEIF [GRIDCODE] = 2 Then
result = "Área de vegetação nativa cadastrada como uso consolidado"
End If‍‍‍‍‍‍‍

Note: you should always return something with an ELSE.

NeilAyres
MVP Alum

Sorry Darren, was looking at something else, then you replied....

0 Kudos
NeilAyres
MVP Alum

In what way doesn't it "work"?

Arc version. Error message etc etc.

Is this something where you are trying to use the field calculator?

0 Kudos
CarlosPires2
New Contributor

Neil,

version 10.2

sintaxe error

0 Kudos
EdwinRoa
Esri Contributor

Hi 

I'm agree with Daren.  You need to store the result in a variable. 

Dim value
If [GRIDCODE] = 0 Then
value = "Não há diferença"
ELSEIF [GRIDCODE] = 1 Then
value = "Área de uso consolidado cadastrada como nativa"
ELSEIF [GRIDCODE] = 2 Then
value = "Área de vegetação nativa cadastrada como uso consolidado"

End If

And put into a calculator. 

0 Kudos