I am trying to use conditional statement to populate a new field using the Field Calculator. I have a column named "Days from Appt." I would like the field to populate if less than 7 days "One week or less." I named this new column Duration. Can someone please help a newbie to programming with this? Can either be in VB or Python. Thanks.
Since you only have one condition why not make it quick
or in totally untested code and assuming your source field is numeric
python parser
def appt(input_field): """no error checking""" if input_field < 7: # assuming a numeric field otherwise int(input_field) val = "One week or less" else: val = str(input_field) return val
field expression !your_field_here!
obviously changing !your_field_here! to you know, your field
Thanks for your response. I forgot to mention that I need to have several if statements. I will have 8-14 days = Two weeks or less, 15-21 = Three weeks or less. Also I have negative days which will be greater than one week, etc.
Also I tried this before I left for the day. I would put the code in the code block and what would I use
for the box under the code block?
the !your_field_here!
for homework...
if a < 7:
val = do blah
elif (a >= 7) and (a < 14):
val = more blah
...
...
else:
val = final blah
return val
Thanks for your help. I'll have to give it a try on Monday. Wish Me Luck. 🙂