<?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 Re: Simple If - Then - Else Programming in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/simple-if-then-else-programming/m-p/51505#M1797</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you want to use the Python parser see the Nested Conditional Operators for some suggestions&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://obidangis.blogspot.ca/2013/12/nested-conditional-operators.html"&gt;http://obidangis.blogspot.ca/2013/12/nested-conditional-operators.html&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 16 Feb 2014 20:27:44 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2014-02-16T20:27:44Z</dc:date>
    <item>
      <title>Simple If - Then - Else Programming</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/simple-if-then-else-programming/m-p/51504#M1796</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Could someone please advise me how do use a simple "if - then - else" construct to take two columns of population data on different dates and compute a new column of the percentage change?&amp;nbsp; I also need to account for potential divide-by-zero errors.&amp;nbsp; I have tried writing straightforward &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if field1 &amp;gt; 0 then &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; (field2 - field1)/field1 &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;else &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;end if (done both with and without the end if)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;but of course this fails.&amp;nbsp; I tried using the example code from one of the knowledgebase articles: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Static lastValue as variant&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim Output As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If IsEmpty(lastValue) Then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Output = 0&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Else&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; Output = (([Increment] - lastValue) / lastValue) * 100&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End If&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lastValue = [Increment]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; but this, too fails.&amp;nbsp; I had even created a field containing the "increment" (but named differently), but with no success.&amp;nbsp; And of course the compiler gives absolutely no idea of what might be wrong.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This should NOT be that hard.&amp;nbsp; What am I doing wrong?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Feb 2014 19:27:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/simple-if-then-else-programming/m-p/51504#M1796</guid>
      <dc:creator>ChrisRautman</dc:creator>
      <dc:date>2014-02-16T19:27:53Z</dc:date>
    </item>
    <item>
      <title>Re: Simple If - Then - Else Programming</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/simple-if-then-else-programming/m-p/51505#M1797</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;If you want to use the Python parser see the Nested Conditional Operators for some suggestions&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://obidangis.blogspot.ca/2013/12/nested-conditional-operators.html"&gt;http://obidangis.blogspot.ca/2013/12/nested-conditional-operators.html&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 16 Feb 2014 20:27:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/simple-if-then-else-programming/m-p/51505#M1797</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2014-02-16T20:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Simple If - Then - Else Programming</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/simple-if-then-else-programming/m-p/51506#M1798</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am assuming you are just using field calculator.&amp;nbsp;&amp;nbsp; I just threw together a shapefile to test your script with three fields [pop_2000], [pop_2010], and [pct_change].&amp;nbsp; You right click on the pct_change field to run field calculator, check the Show Codeblock box, enter just the word Output in the Codeblock box, and then you can do something basic like this in the Pre-Logic Script Code box:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;If IsEmpty([pop_2000]) or IsEmpty([pop_2010]) Then
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Output = -9999
Else
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Output = (([pop_2010] - [pop_2000]) / [pop_2000]) * 100
End If
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't even bother with dim statements because it does not care.&amp;nbsp; You can also use IsNull if you so desire.&amp;nbsp; I originally had set the Output to NULL if one of the populations was empty but it would not accept it so I used -9999 to show it was invalid.&amp;nbsp; Always make sure you put column names in square brackets, and if for some odd reason one of your columns is a string, you may have to use the val function to convert it to a number.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 21:59:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/simple-if-then-else-programming/m-p/51506#M1798</guid>
      <dc:creator>NeoGeo</dc:creator>
      <dc:date>2021-12-10T21:59:11Z</dc:date>
    </item>
  </channel>
</rss>

