Is This Content Helpful?
How can we make this better? Please provide as much detail as possible.
Note: This article pertains to ArcGIS versions 8.x. Later versions of ArcGIS may contain different functionality, as well as different names and locations for menus, commands and geoprocessing tools.
The sample code in this article returns the distance between two features using VBA and ArcObjects.
Note: Support for Visual Basic for Applications (VBA) for ArcMap and ArcCatalog ended with the ArcGIS 10.2.2 release, and Esri has not included VBA compatibility setups since version 10.5. See: ArcGIS Desktop and VBA Moving Forward
Note: For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
Dim pDoc As IMxDocument Dim pMap As IMap Set pDoc = ThisDocument Set pMap = pDoc.FocusMap Dim pFLayer As IFeatureLayer Set pFLayer = pMap.Layer(0) Dim pFeat As IFeature Dim pFeat1 As IFeature Dim dDist As Double Dim pFc As IFeatureClass Set pFc = pFLayer.FeatureClass 'Get features 1 and 4 Set pFeat = pFc.GetFeature(1) Set pFeat1 = pFc.GetFeature(4) Dim pProxOp As IProximityOperator Dim pGeom As IGeometry Dim pGeom1 As IGeometry Set pGeom1 = pFeat1.Shape Set pGeom = pFeat.Shape Set pProxOp = pGeom 'Find the Distance dDist = pProxOp.ReturnDistance(pGeom1) MsgBox "The distance is: " & dDist