I am trying to add a line to an existing script. I have created a new attribute field [PlantDate], and need it to reflect in the label expression.
This is the current script:
Function FindLabel ( [FieldName], [FarmAcres], [FutureCrop1], [FutureCrop2], [FutureCrop3], [IrrigationType] )
If (IsNull ([FutureCrop2]) AND IsNull ([FutureCrop3])) Then
FindLabel = "Field #" + [FieldName] & vbCrLf & [FarmAcres] + " Acres" & vbCrLf& [FutureCrop1] & vbCrLf& [IrrigationType]
ElseIf IsNull ([FutureCrop3]) Then
FindLabel = "Field #" + [FieldName] & vbCrLf & [FarmAcres] + " Acres" & vbCrLf& [FutureCrop1] + "/ " + [FutureCrop2] & vbCrLf& [IrrigationType]
Else
FindLabel = "Field #" + [FieldName] & vbCrLf & [FarmAcres] + " Acres" & vbCrLf& [FutureCrop1] + "/ " + [FutureCrop2] + "/ " + [FutureCrop3] & vbCrLf& [IrrigationType]
End If
End Function
I need it to include the new "plant date" field [PlantDate] on the next line. I did the following script but it is only showing the features of the original script so I am unsure what I am doing wrong (note: the field is not <null>, I have a value in the field for this polygon). This is the script I tried:
Function FindLabel ( [FieldName], [FarmAcres], [FutureCrop1], [FutureCrop2], [FutureCrop3], [IrrigationType], [PlantDate] )
If (IsNull ([FutureCrop2]) AND IsNull ([FutureCrop3])) Then
FindLabel = "Field #" + [FieldName] & vbCrLf & [FarmAcres] + " Acres" & vbCrLf& [FutureCrop1] & vbCrLf& [IrrigationType] & vbCrLf& [PlantDate]
ElseIf IsNull ([FutureCrop3]) Then
FindLabel = "Field #" + [FieldName] & vbCrLf & [FarmAcres] + " Acres" & vbCrLf& [FutureCrop1] + "/ " + [FutureCrop2] & vbCrLf& [IrrigationType] & vbCrLf& [PlantDate]
Else
FindLabel = "Field #" + [FieldName] & vbCrLf & [FarmAcres] + " Acres" & vbCrLf& [FutureCrop1] + "/ " + [FutureCrop2] + "/ " + [FutureCrop3] & vbCrLf& [IrrigationType] & vbCrLf& [PlantDate]
End If
End Function
The system says it is valid, but it is not showing that added [PlantDate] information on the polygon. Refreshing and reloading is not correcting it either. Ideally, I would like it to have the text "Plant Date" following the value (like I have ' + " Acres" ' for field acres) but it says there is an error when I attempt, and it blues out the word "date."
Any help/advice would be great appreciated! Thank you.
Solved! Go to Solution.
Sound like giving up talk.
Just a typo on the 3rd Line, also forgot to include irrigationtype.
def FindLabel([FieldName], [FarmAcres], [FutureCrop1], [FutureCrop2], [FutureCrop3], [IrrigationType], [PlantDate]):
if [FieldName] is not None and [FarmAcres] is not None and [PlantDate] is not None and [IrrigationType] is not None:
if [FutureCrop2] is None and [FutureCrop3] is None:
result = "Field #" + [FieldName] + "\n" + str([FarmAcres]) + " Acres" + "\n" + [FutureCrop1] + "\n" + [IrrigationType] + "\n" + str([PlantDate])
elif [FutureCrop3] is None:
result = "Field #" + [FieldName] + "\n" + str([FarmAcres]) + " Acres" + "\n" + [FutureCrop1] + "/" + [FutureCrop2] + "\n" + [IrrigationType] + "\n" + str([PlantDate])
else:
result = "Field #" + [FieldName] + "\n" + str([FarmAcres]) + " Acres" + "\n" + [FutureCrop1] + "/" + [FutureCrop2] + "/" + [FutureCrop3] + "\n" + [IrrigationType] + "\n" + str([PlantDate])
return result
else:
return None
Haha! 🙂
The error now was
Error code 2 on line 98
Expected 'Then'
Hmmm, I'm thinking there's something in your data, I tested the expression on a made up sample dataset and it worked.
Are you able to share the data or table? Did you use the exact code in my last reply? Can you screenshot your label properties window?
If not, I'd advice exporting say 1 or 2 features that appear to be attributed correctly, then testing the expression on just those.
Sorry this took some time to reply - I was pulled to another project and wasn't able to work on this .
I retried my original expression today on a different map and it seemed to have worked. I'm not sure why but it seems to be an issue with that original map I was working on. I appreciate your help and input on this!! Thank you!