I know this question has been asked a hundred times on here, for example:
- Basic If/Then in Python Parser of ArcGIS Field Calculator?
- Using if/elif/else statements in ArcGIS Field Calculator?
- Checking for values in one column and do something in another using ArcGIS Field Calculator?
- https://community.esri.com/thread/21689
but I just can't get my code to work. I am trying to do a simple if/then statement in field calculator. I have a column (risk_value) I want to populate based on the values in the other (risk_color). There are only four values in Risk_color: Green, yellow, red, null.
I tried writing code in VBA:
Pre-logic script Code:
Dim val
If [RISK_COLOR] = "Green" Then
val = "Low"
elseif [RISK_COLOR] = "Yellow" Then
val = "Medium"
elseif [RISK_COLOR] = "Red" Then
val = "High"
elseif [RISK_COLOR] = "<Null>" Then
val = "<Null>"
end if
RISK_VALUE=
val
Error executing function.
Then I tried python string:
def Value(color):
if (color == 'Green'):
return "Low"
elif (color == 'Yellow'):
return "Medium"
elif (color == 'Red'):
return "High"
else:
return "<Null>"
RISK_VALUE=Value(!RISK_COLOR!)
Error executing function.
What am I doing wrong?
'Red''
, but good catch.