<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Using Python in Calculate Field in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85562#M2944</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;2nd question:&lt;BR /&gt;How can i populate a field with the maximum value of 3 other fields using the Field Calculator (again in Model Builder).&lt;BR /&gt;&lt;BR /&gt;Thanks for your ideas!&lt;BR /&gt;&lt;BR /&gt;David&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi David,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As my tendencies run to Python, I would tackle this with the Calculate Field tool using Python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;An expression something like below, will return the largest of 3 field values (no code block necessary for this one).&amp;nbsp; Of course, adjust your field names as needed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;max([!FieldA!, !FieldB!, !FieldC!])&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Dave&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 21 Apr 2010 19:00:44 GMT</pubDate>
    <dc:creator>DavidWynne</dc:creator>
    <dc:date>2010-04-21T19:00:44Z</dc:date>
    <item>
      <title>Calculate Field VBA Statement If...Then...Else in ModelBuilder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85559#M2941</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to build a model which calculates the fields of a colum of a table using an if...then...else statement.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;After typing the expression in the Pre-Logic VBA Script Code window I tried to run the model but the fields wouldn't change values. When i do the same thing outside the model builder it works. :confused:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Why?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2nd question:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;How can i populate a field with the maximum value of 3 other fields using the Field Calculator (again in Model Builder).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks for your ideas!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;David&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Apr 2010 11:06:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85559#M2941</guid>
      <dc:creator>DavidJud</dc:creator>
      <dc:date>2010-04-21T11:06:36Z</dc:date>
    </item>
    <item>
      <title>Calculate Field VBA Statement If...Then...Else in ModelBuilder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85560#M2942</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;(edit, read the question too quickly)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Apr 2010 12:36:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85560#M2942</guid>
      <dc:creator>ToreBorvik</dc:creator>
      <dc:date>2010-04-21T12:36:53Z</dc:date>
    </item>
    <item>
      <title>If...then...else</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85561#M2943</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Without seeing the code, I can only guess...but I'll share what I've learned about If...then...else statements in calculate field...it's all in how you structure the line breaks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Example 1:&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;dim result as string&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if [location] = â?�HOMEâ?� then result = â?�Aâ?�&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if [location] = â?�WORKâ?� then result = â?�Bâ?�&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Example 2:&lt;/STRONG&gt;&lt;SPAN&gt; (this works too but only as one line) &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;dim output as double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if [LOCATIONID]=100 then output=100 else if [LOCATIONID] = 101 then output = 101 else output = 102 &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Example 3:&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp; The following code will work &lt;/SPAN&gt;&lt;STRONG&gt;BUT will give the wrong result!!&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;dim output as double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if [LOCATIONID] = 100 then output = 100 else&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if [LOCATIONID] = 101 then output = 101 else output = 102 &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Example 4:&lt;/STRONG&gt;&lt;SPAN&gt; This is the way it should work, but the line breaks &lt;/SPAN&gt;&lt;STRONG&gt; must be correct&lt;/STRONG&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;dim output as double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if [LOCATIONID] = 100 then &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output=100 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;elseif [LOCATIONID] = 101 then &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output = 101 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;else &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output = 102&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end if&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If thereâ??s anything following the â??thenâ?? it assumes a single-line format which, of course, is quite different from the multi-line format.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;STRONG&gt;Example 5: &lt;/STRONG&gt;&lt;SPAN&gt; An alternative form is the &lt;/SPAN&gt;&lt;STRONG&gt;SELECT CASE â?¦ CASE â?¦ ELSE ... END SELECT&lt;/STRONG&gt;&lt;SPAN&gt; format, which seems to be a tad more consistent:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;dim output as double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;select case [LOCATIONID] &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; case 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; output = 101&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; case 101&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; output = 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; case 102&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; output = 104&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; else&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; output = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end select&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good luck!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jim G.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;MN Dept. Of Agriculture&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Apr 2010 13:34:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85561#M2943</guid>
      <dc:creator>JamesGonsoski</dc:creator>
      <dc:date>2010-04-21T13:34:05Z</dc:date>
    </item>
    <item>
      <title>Using Python in Calculate Field</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85562#M2944</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&lt;BR /&gt;2nd question:&lt;BR /&gt;How can i populate a field with the maximum value of 3 other fields using the Field Calculator (again in Model Builder).&lt;BR /&gt;&lt;BR /&gt;Thanks for your ideas!&lt;BR /&gt;&lt;BR /&gt;David&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Hi David,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;As my tendencies run to Python, I would tackle this with the Calculate Field tool using Python.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;An expression something like below, will return the largest of 3 field values (no code block necessary for this one).&amp;nbsp; Of course, adjust your field names as needed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;max([!FieldA!, !FieldB!, !FieldC!])&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;-Dave&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Apr 2010 19:00:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85562#M2944</guid>
      <dc:creator>DavidWynne</dc:creator>
      <dc:date>2010-04-21T19:00:44Z</dc:date>
    </item>
    <item>
      <title>same problem with if..then...else</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85563#M2945</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey Dave,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I have exactly the same problem with the calculator. The VBA statement works ... but not in the ModelBuilder. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Did you manage to solve the problem?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I already tried Jims statements - also not working in the modelbuilder. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jean&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 29 Apr 2010 00:32:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85563#M2945</guid>
      <dc:creator>JeanGroth</dc:creator>
      <dc:date>2010-04-29T00:32:26Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field VBA Statement If...Then...Else in ModelBuilder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85564#M2946</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Someone who knows more about programming than I told me that the case statement should have a "case else" statement instead of just "else".&amp;nbsp; I then got it to work in both table view and Model Builder.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jun 2010 15:34:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85564#M2946</guid>
      <dc:creator>KimberlyMeinert</dc:creator>
      <dc:date>2010-06-09T15:34:35Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field VBA Statement If...Then...Else in ModelBuilder</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85565#M2947</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Someone who knows more about programming than I told me that the case statement should have a "case else" statement instead of just "else".&amp;nbsp; I then got it to work in both table view and Model Builder.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;My bad. You are absolutely right. That example of mine should look like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Example 5: An alternative form is the SELECT CASE �?� CASE �?� ELSE ... END SELECT format, which seems to be a tad more consistent:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;dim output as double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;select case [LOCATIONID]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;case 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output = 101&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;case 101&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output = 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;case 102&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output = 104&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;case else&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;output = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end select&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Jim&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 09 Jun 2010 16:56:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-vba-statement-if-then-else-in/m-p/85565#M2947</guid>
      <dc:creator>JamesGonsoski</dc:creator>
      <dc:date>2010-06-09T16:56:14Z</dc:date>
    </item>
  </channel>
</rss>

