HOME Free ArcGIS tools HOME
Free ArcView 3.x extensions Free functions of ET GeoWizards 8.6 EasyCalculate


EasyCalculate Plus

EasyCalculate Plus shows how the expressions of EasyCalculate can be used programmatically in your VB or VBA code. 

EC Plus consists of two VB modules (included in the download)

  1. EC_RunCalculator.bas - Has a single SUB procedure - "EC_Run_Calc", that illustrates how to use the FieldCalculator programmatically. The procedure works on the selected layer in the ArcMap TOC. The only changes the user needs to do are:
    • Change the  name of the field to be calculated (the field must be of the appropriate type for the calculations performed)
    • Change the name of the Calculation procedure to be called (see the procedures available in EC_Expressions.bas and How to add a new procedure)
    • Some of the procedures might require additional parameters to be passed.
  2. EC_Expressions.bas - Contains several sample calculation procedures. Any of the expressions available in EasyCalculate can be easily added as a Sub procedure to the EC_Expressions module - see How to add a new procedure

How to run EC Plus:

  1. In ArcMap: Go to Tools ==> Macros ==> Visual Basic Editor
  2. In the Visual Basic Editor: Right click on Project ==> Import file ==> Navigate to the location of the EC Plus ==> Select one of the *.bas file ==> Click the Open button
  3. Do the same to load the second file
  4. Make sure that in ArcMap the correct layer is selected
  5. Open the EC_Run_Calc module ==> Make the changes required (see above) and run the procedure

Procedures available in EC Plus - see EasyCalculate page for description

  • polygon_Return_Area(sPreExpression As String, sExpression As String)
  • shape_Return_Length(sPreExpression As String, sExpression As String)
  • polyline_Get_X_MiddlePoint(sPreExpression As String, sExpression As String, _
    dDistance As Double, bAsRatio As Boolean)
  • mp_get_X_Center(sPreExpression As String, sExpression As String)
  • polyline_Flip(sPreExpression As String, sExpression As String)
  • polygon_Get_X_Center(sPreExpression As String, sExpression As String)
  • point_Get_X(sPreExpression As String, sExpression As String)
  • point_Get_M(sPreExpression As String, sExpression As String)

How to add a new procedure:

  1. Open EC_Expressions module.
  2. Create a new Sub. Make sure that the name of the procedure is unique for the module

    Public Sub point_Get_Y(sPreExpression As String, sExpression As String)

    End Sub

  3. Go to ArcMap ==> Open an attribute table ==> Right click on a field ==> Calculate Values ==> In the Field Calculator dialog click Load ==> Select an expression from the EasyCalculate ==> Copy the code from the Pre-Logic box. ==> Close the field calculator using the Cancel button
  4. Go to VB Editor ==>  paste the code in the procedure created in step 2 above

    Public Sub point_Get_Y(sPreExpression As String, sExpression As String)
      Dim pMxDoc As IMxDocument
      Dim pMap As IMap
      Dim pPoint As IPoint
      Dim dY As Double
      Set pMxDoc = ThisDocument
      Set pMap = pMxDoc.FocusMap
      If (Not IsNull([Shape])) Then
        Set pPoint = [Shape]
        pPoint.Project pMap.SpatialReference
        dY = pPoint.Y
      End If
    End Sub

  5. Edit the code as below:

    Public Sub point_Get_Y(sPreExpression As String, sExpression As String)
      sPreExpression = _
      "Dim pMxDoc As IMxDocument" & vbNewLine & _
      "Dim pMap As IMap" & vbNewLine & _
      "Dim pPoint As IPoint" & vbNewLine & _
      "Dim dY As Double" & vbNewLine & _
      "Set pMxDoc = ThisDocument" & vbNewLine & _
      "Set pMap = pMxDoc.FocusMap" & vbNewLine & _
      "If (Not IsNull([Shape])) Then" & vbNewLine & _
      "  Set pPoint = [Shape]" & vbNewLine & _
      "  pPoint.Project pMap.SpatialReference" & vbNewLine & _
      "  dY = pPoint.Y" & vbNewLine & _
      "End If"
      sExpression = "dY"
    End Sub

  6. The new procedure is ready to be run

 

For any comments and enquiries contact: webmaster@ian-ko.com
Esri and all Esri products mentioned are trademarks of Environmental Systems Research Institute, Inc.
Copyright: Ianko Tchoukanski