if !myField! == 'NULL' will not test for a null value. That will test a for a string equal to 'NULL'. Use:
if !myField! is None:
To accomlish your task, define a python function in the pre-logic code block and use that function in the expression window. The following code sample pulls the first token from a '-' delimited string.
Try this (edited per @alpha-beta-soup comment):
def myFunction (inter, prop, patch, shp, nat, edge):
myList = [inter, prop, patch, shp, nat, edge]
myList.sort()
myDict = {'Interconnectivity' : inter,
'PropCover' : prop,
'PatchSize' : patch,
'ShapeIndex': shp,
'Naturalness' : nat,
'EdgeNat' : edge}
myVal = 101 # using 101 as a max + 1 possible value; adjust if needed
myReturn = ''
for k, v in myDict.iteritems():
if v < myVal:
myVal = v
myReturn = k
return myReturn
Note that if you have two matching low values, there's nothing to select one over the other. That would require additional checking based on whatever your criteria is. Since a dictionary is unordered, you can't control it that way.
Here's another way without dictionaries, with an optional clause for ties. You may want different logic in case of ties.
def myFunction2 (inter, prop, patch, shp, nat, edge):
# use tuples to ensure value order
myScoreTuple = (prop, patch, shp, nat, edge)
myTextTuple = ('PropCover',
'PatchSize',
'ShapeIndex',
'Naturalness',
'EdgeNat')
# initialize values
myLowValue = inter
myReturn = 'Interconnectivity'
# now check for any lower value
for i in range(len(myScoreTuple)):
if myScoreTuple[i] < myLowValue:
myLowValue = myScoreTuple[i]
myReturn = myTextTuple[i]
# optional - add multiple text values in case of tie. Remove if unneeded
elif myScoreTuple[i] == myLowValue:
myReturn = ', '.join((myReturn, myTextTuple[i]))
return myReturn
Best Answer
For VB, something like this should work, I think:
Pre-logic script code:
asp_code =
In Python, I think it would be something like this (though I don't have ArcGIS 10 so I can't check):
Pre-logic script code:
asp_code =
The error message saying that the "calculated value is invalid" is a bit strange. Perhaps double-check that your
asp_code
field is offloat
ordouble
data type (notinteger
), and that you have all of the options in the grid_code field covered by your if statements? Sorry if that's too obvious, but it's all I can think of at the moment. Good luck!