Using If Statements in Field Calculator

883
3
07-01-2011 09:56 AM
ColterSikora1
New Contributor II
Hello,

I am trying to use Field Calculator to collect values from multiple fields in a feature class.  I only want records with no value to be filled in with the Field Calculator result.  Since I am setting this up for automatic updates, I am trying to program this within Model Builder.  However, my relative lack of programming experience is holding me back. Right now, my attept to program this goes as follows:

(Using Python as the Parse)
Pre-Logic Script Code:
If !STR_ADD! = " " Then

STR_ADD=
!STR_NUM! +" " + !STR_PRE_DIR! +" " + !STR_PRE_TYPE! +" " + !STR_NAM!

Essentially, if my STR_ADD field is empty, I want to fill it with the combined values of the other four fields mentioned.  I want to continue with the code to add values from other fields when some of my records remain empty.  However, if I can't get this first part completed, it is hard to continue.

Thank you for your help in advance!

Colter
0 Kudos
3 Replies
DaleHoneycutt
Regular Contributor
Have a look at this blog article.

Although it doesn't specifically address your problem, it shows how to deal with null values and multiple fields.
0 Kudos
curtvprice
MVP Esteemed Contributor
Hello,

I am trying to use Field Calculator to collect values from multiple fields in a feature class.  I only want records with no value to be filled in with the Field Calculator result. 


It may be easier to pass the input through the Select Layer By Attribute tool first, selecting for:

"STR_ADD" IS NOT NULL AND "STR_ADD" <> ''

so the calculation will only be applied to the selected rows.
0 Kudos
DaleHoneycutt
Regular Contributor
Curtis: yep, good point
0 Kudos