<?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: Converting VBScript to Arcade or Python to calculate a field in Developers Questions</title>
    <link>https://community.esri.com/t5/developers-questions/converting-vbscript-to-arcade-or-python-to/m-p/1223368#M6376</link>
    <description>&lt;P&gt;Are each of your fields numeric? In Arcade, you can use the &lt;A href="https://developers.arcgis.com/arcade/function-reference/text_functions/#text" target="_self"&gt;Text&lt;/A&gt; function to pad them with 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var X;
var insee = $feature.INSEE;
if (Count(Text(INSEE) &amp;lt; 3) {
  X = '????';
} else {
  X = Text(insee, '00000')
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the fields are strings, then you would have to use this method, using the &lt;A href="https://developers.arcgis.com/arcade/function-reference/logical_functions/#when" target="_self"&gt;When&lt;/A&gt; function and &lt;A href="https://developers.arcgis.com/arcade/guide/logic/#template-literals" target="_self"&gt;Template literals&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var insee = #feature.INSEE;
var x = When(Count(insee) == 4, `0${insee}`,
              Count(insee) == 3, `00${insee}`,
              '?????');&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 19 Oct 2022 15:22:59 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2022-10-19T15:22:59Z</dc:date>
    <item>
      <title>Converting VBScript to Arcade or Python to calculate a field</title>
      <link>https://community.esri.com/t5/developers-questions/converting-vbscript-to-arcade-or-python-to/m-p/1223288#M6374</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I have the following VB Script expression to calculate a field in a shapefile.&lt;/P&gt;&lt;P&gt;Since ArcGIS pro doesn’t read VB Script for the field calculation, could someone help me converting it to Arcade or Python ?&lt;/P&gt;&lt;P&gt;I unfortunately don’t have the skills for it.&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dim X&lt;/P&gt;&lt;P&gt;if len( [INSEE]) =4 then&lt;/P&gt;&lt;P&gt;X = "0" &amp;amp; [INSEE]&lt;/P&gt;&lt;P&gt;Elseif&amp;nbsp; len( [INSEE])=3 then&lt;/P&gt;&lt;P&gt;X = "00" &amp;amp; [INSEE]&lt;/P&gt;&lt;P&gt;Elseif&amp;nbsp; len( [INSEE])&amp;lt;3 then&lt;/P&gt;&lt;P&gt;X = "?????"&lt;/P&gt;&lt;P&gt;Else X = [INSEE]&lt;/P&gt;&lt;P&gt;end if&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dim N&lt;/P&gt;&lt;P&gt;if len( [PREFIXE])=2 then&lt;/P&gt;&lt;P&gt;N = "0" &amp;amp; [PREFIXE]&lt;/P&gt;&lt;P&gt;Elseif len( [PREFIXE])=1 then&lt;/P&gt;&lt;P&gt;N = "00" &amp;amp; [PREFIXE]&lt;/P&gt;&lt;P&gt;Else N = [PREFIXE]&lt;/P&gt;&lt;P&gt;end if&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dim Y&lt;/P&gt;&lt;P&gt;If [SECTFEUI] =" " then&lt;/P&gt;&lt;P&gt;Y="????"&lt;/P&gt;&lt;P&gt;Elseif [SECTFEUI] ="0" then&lt;/P&gt;&lt;P&gt;Y="????"&lt;/P&gt;&lt;P&gt;Elseif len( [SECTFEUI]) =3 then&lt;/P&gt;&lt;P&gt;Y = "0" &amp;amp; [SECTFEUI]&lt;/P&gt;&lt;P&gt;Elseif len( [SECTFEUI]) =2 then&lt;/P&gt;&lt;P&gt;Y = "00" &amp;amp; [SECTFEUI]&lt;/P&gt;&lt;P&gt;Elseif len( [SECTFEUI]) =1 then&lt;/P&gt;&lt;P&gt;Y = "000" &amp;amp; [SECTFEUI]&lt;/P&gt;&lt;P&gt;Else Y = [SECTFEUI]&lt;/P&gt;&lt;P&gt;end if&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;dim Z&lt;/P&gt;&lt;P&gt;if [PARCELLE] ="0" then&lt;/P&gt;&lt;P&gt;Z="????"&lt;/P&gt;&lt;P&gt;Elseif len( [PARCELLE])=3 then&lt;/P&gt;&lt;P&gt;Z = "0" &amp;amp; [PARCELLE]&lt;/P&gt;&lt;P&gt;Elseif len( [PARCELLE])=2 then&lt;/P&gt;&lt;P&gt;Z = "00" &amp;amp; [PARCELLE]&lt;/P&gt;&lt;P&gt;Elseif len( [PARCELLE]) =1 then&lt;/P&gt;&lt;P&gt;Z = "000" &amp;amp; [PARCELLE]&lt;/P&gt;&lt;P&gt;Else Z = [PARCELLE]&lt;/P&gt;&lt;P&gt;end if&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;__esri_field_calculator_splitter__&lt;/P&gt;&lt;P&gt;KEY=X&amp;amp;N&amp;amp;Y&amp;amp;Z&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 13:11:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/converting-vbscript-to-arcade-or-python-to/m-p/1223288#M6374</guid>
      <dc:creator>MoniqueWolff</dc:creator>
      <dc:date>2022-10-19T13:11:10Z</dc:date>
    </item>
    <item>
      <title>Re: Converting VBScript to Arcade or Python to calculate a field</title>
      <link>https://community.esri.com/t5/developers-questions/converting-vbscript-to-arcade-or-python-to/m-p/1223368#M6376</link>
      <description>&lt;P&gt;Are each of your fields numeric? In Arcade, you can use the &lt;A href="https://developers.arcgis.com/arcade/function-reference/text_functions/#text" target="_self"&gt;Text&lt;/A&gt; function to pad them with 0.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var X;
var insee = $feature.INSEE;
if (Count(Text(INSEE) &amp;lt; 3) {
  X = '????';
} else {
  X = Text(insee, '00000')
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If the fields are strings, then you would have to use this method, using the &lt;A href="https://developers.arcgis.com/arcade/function-reference/logical_functions/#when" target="_self"&gt;When&lt;/A&gt; function and &lt;A href="https://developers.arcgis.com/arcade/guide/logic/#template-literals" target="_self"&gt;Template literals&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var insee = #feature.INSEE;
var x = When(Count(insee) == 4, `0${insee}`,
              Count(insee) == 3, `00${insee}`,
              '?????');&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 19 Oct 2022 15:22:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/converting-vbscript-to-arcade-or-python-to/m-p/1223368#M6376</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2022-10-19T15:22:59Z</dc:date>
    </item>
    <item>
      <title>Re: Converting VBScript to Arcade or Python to calculate a field</title>
      <link>https://community.esri.com/t5/developers-questions/converting-vbscript-to-arcade-or-python-to/m-p/1224673#M6380</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;Thank you very much for your answer.&lt;/P&gt;&lt;P&gt;Some of my fields are numeric and some of them are strings.&lt;/P&gt;&lt;P&gt;I finally managed to do it using Python 3 like this :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;def concatspecial(INSEE,PREFIXE,SECTFEUI,PARCELLE):&lt;/P&gt;&lt;P&gt;if len(str(INSEE))==4:&lt;BR /&gt;x = "0"+INSEE&lt;BR /&gt;elif len(str(INSEE))==3:&lt;BR /&gt;x = "00"+INSEE&lt;BR /&gt;elif len(str(INSEE))&amp;lt;3:&lt;BR /&gt;x="?????"&lt;BR /&gt;else:&lt;BR /&gt;x=INSEE&lt;/P&gt;&lt;P&gt;if len(str(PREFIXE))==2:&lt;BR /&gt;n="0"+str(PREFIXE)&lt;BR /&gt;elif len(str(PREFIXE))==1:&lt;BR /&gt;n="00"+str(PREFIXE)&lt;BR /&gt;else:&lt;BR /&gt;n=PREFIXE&lt;/P&gt;&lt;P&gt;if SECTFEUI==" ":&lt;BR /&gt;y = "????"&lt;BR /&gt;elif SECTFEUI=="0":&lt;BR /&gt;y="????"&lt;BR /&gt;elif len(SECTFEUI)==3:&lt;BR /&gt;y="0"+SECTFEUI&lt;BR /&gt;elif len(SECTFEUI)==2:&lt;BR /&gt;y="00"+SECTFEUI&lt;BR /&gt;elif len(SECTFEUI)==1:&lt;BR /&gt;y ="000"+SECTFEUI&lt;BR /&gt;else:&lt;BR /&gt;y = SECTFEUI&lt;/P&gt;&lt;P&gt;if PARCELLE=="0":&lt;BR /&gt;z="????"&lt;BR /&gt;elif len(str(PARCELLE))==3:&lt;BR /&gt;z = "0"+str(PARCELLE)&lt;BR /&gt;elif len(str(PARCELLE))==2:&lt;BR /&gt;z = "00"+str(PARCELLE)&lt;BR /&gt;elif len(str(PARCELLE))==1 :&lt;BR /&gt;z = "000" + str(PARCELLE)&lt;BR /&gt;else:&lt;BR /&gt;z = PARCELLE&lt;BR /&gt;return str(x)+str(n)+str(y)+str(z)&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Have a good day !&lt;/P&gt;</description>
      <pubDate>Mon, 24 Oct 2022 13:35:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/developers-questions/converting-vbscript-to-arcade-or-python-to/m-p/1224673#M6380</guid>
      <dc:creator>MoniqueWolff</dc:creator>
      <dc:date>2022-10-24T13:35:16Z</dc:date>
    </item>
  </channel>
</rss>

