<?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: Calculate Field Error VBScripting in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-error-vbscripting/m-p/502271#M16681</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just FYI, you can calculate the x-centroid using the "PYTHON" parser (v9.2) in the Calculate Field tool (expression stolen from &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000"&gt;this help page&lt;/A&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;float(!SHAPE.CENTROID!.split()[0])&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 25 Apr 2012 19:19:43 GMT</pubDate>
    <dc:creator>DarrenWiens2</dc:creator>
    <dc:date>2012-04-25T19:19:43Z</dc:date>
    <item>
      <title>Calculate Field Error VBScripting</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-error-vbscripting/m-p/502268#M16678</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello all! The company I am currently working for has decided to migrate from ArcGIS 9.3 to 10.0 recently and we are having difficulty using a few of our Arc 9.3 models that utilize the Calculate Field tool. They were written in VBA and I need to get them to work using VBScript. The following bit of code is intended to calculate the x coordinate of the centre of a harvesting block and put it in a field.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Field Name: xcoord&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression: dblX&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression Type: VB&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code Block:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dblX as Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pArea as IArea&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pArea = [Shape]&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dblX = pArea.Centroid.X&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am aware that you cannot have "as Double" in Dim statements with VBSand I have tried to remove those without any luck. I apologize in advance for my lack of scripting/programming language. I receive the following error once the model finished running:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;General error executing calculator.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 999999: Error executing function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Expected end of statement&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Calculate Field (3)).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I also get the same error when the following bit of code runs in another calculate field tool within the same model.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Field Name: LONGITUDE&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression: sDMS&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression Type: VB&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code Block:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pArea As IArea&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dblX As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dVal As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dD As Double, dM As Double, dS As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim dM1 As Double, dS1 As Double&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim sD As String, sM As String, sS As String&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim sSuf As String&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim sType As String&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim sDMS As String&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim sDeg As String, sMin As String, sSec As String&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim inumdec As Integer&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pSpatRefFact As ISpatialReferenceFactory2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pSpatRefFact = New SpatialReferenceEnvironment&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pCoordSys As IGeographicCoordinateSystem&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pCoordSys = pSpatRefFact.CreateGeographicCoordinateSystem(esriSRGeoCS_NAD1983)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Dim pNewSpRef As ISpatialReference&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pNewSpRef = pCoordSys&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Set pArea = [Shape]&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;pArea.Centroid.Project pNewSpRef&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dblX = pArea.Centroid.X&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dVal = dblX&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;sDeg = "d"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sMin = Chr(39)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sSec = Chr(34)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;inumdec = 2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sType = "dms"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;dVal = Abs(dVal)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dD = Int(dVal)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sD = CStr(dD)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dM = (dVal - dD) * 60&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dM1 = Int(dM)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If (sType = "dms") Then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If (Len(CStr(dM1)) = 1) Then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sM = "0" &amp;amp; CStr(dM1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Else&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sM = CStr(dM1)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End If&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dS = FormatNumber(((dM - dM1) * 60), inumdec)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dS1 = Int(dS)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If (Len(CStr(dS1)) = 1) Then&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sS = "0" &amp;amp; CStr(dS)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Else&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sS = CStr(dS)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End If&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sDMS = sD &amp;amp; sDeg &amp;amp; " " &amp;amp; sM &amp;amp; sMin &amp;amp; " " &amp;amp; sS &amp;amp; sSec&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Else&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sM = CStr(FormatNumber(dM, inumdec))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;sDMS = sD &amp;amp; sDeg &amp;amp; " " &amp;amp; sM &amp;amp; sMin&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;End If&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any assistance with getting this to run using VBScripting would be most appreciated. Thanks in advance!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Steve&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 24 Apr 2012 16:48:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-error-vbscripting/m-p/502268#M16678</guid>
      <dc:creator>SteveRichards2</dc:creator>
      <dc:date>2012-04-24T16:48:39Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field Error VBScripting</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-error-vbscripting/m-p/502269#M16679</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hello all! The company I am currently working for has decided to migrate from ArcGIS 9.3 to 10.0 recently and we are having difficulty using a few of our Arc 9.3 models that utilize the Calculate Field tool. They were written in VBA and I need to get them to work using VBScript. The following bit of code is intended to calculate the x coordinate of the centre of a harvesting block and put it in a field.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Field Name: xcoord&lt;BR /&gt;Expression: dblX&lt;BR /&gt;Expression Type: VB&lt;BR /&gt;&lt;BR /&gt;Code Block:&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Dim dblX as Double
Dim pArea as IArea
Set pArea = [Shape]
dblX = pArea.Centroid.X
&lt;/PRE&gt;&lt;BR /&gt; &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;From the online help:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Use Python if you want access to geoprocessing functionality, including feature geometry....If you have VBA code from past releases that use ArcObjects, you will need to modify your calculations to work in 10.0.&lt;BR /&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It sounds painful, but rewriting it in Python won't be as hard as you may think. The arcpy methods handling feature geometry are less complex to work with than ArcObjects.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Arc 10 Help: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;A href="&amp;lt;/span&amp;gt;&amp;lt;a" target="_blank" rel="nofollow noopener noreferrer"&gt;Calculate Field examples&lt;/A&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&lt;SPAN&gt;&lt;A href="&amp;lt;/span&amp;gt;&amp;lt;a" target="_blank" rel="nofollow noopener noreferrer"&gt;Working" rel="nofollow" target="_blank"&amp;gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//002z0000001s000000]Working&lt;/A&gt;&lt;SPAN&gt; with geometry in Python&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also, there are tools available that could be combined to set up an easier-to-maintain workflow than your VBA scripts; a ModelBuilder model may even accomplish what you need using tools like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Feature To Point&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Add XY&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Convert Coordinate Notation&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 22:02:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-error-vbscripting/m-p/502269#M16679</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T22:02:49Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field Error VBScripting</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-error-vbscripting/m-p/502270#M16680</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you for the reply. Learning Python is on the agenda for the near future and I will eventually rewrite the VBA code to Python. For now I just simplified the models in order to get them to produce what I need. Thanks for your help.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Apr 2012 18:59:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-error-vbscripting/m-p/502270#M16680</guid>
      <dc:creator>SteveRichards2</dc:creator>
      <dc:date>2012-04-25T18:59:40Z</dc:date>
    </item>
    <item>
      <title>Re: Calculate Field Error VBScripting</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/calculate-field-error-vbscripting/m-p/502271#M16681</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Just FYI, you can calculate the x-centroid using the "PYTHON" parser (v9.2) in the Calculate Field tool (expression stolen from &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00170000004m000000"&gt;this help page&lt;/A&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro"&gt;float(!SHAPE.CENTROID!.split()[0])&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 25 Apr 2012 19:19:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/calculate-field-error-vbscripting/m-p/502271#M16681</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2012-04-25T19:19:43Z</dc:date>
    </item>
  </channel>
</rss>

