Is This Content Helpful?
We're glad to know this article was helpful.
The sample code in this article returns the distance between two features using VBA and ArcObjects.
Note: For more information on creating a UIControl, see the ArcGIS Desktop Help topic: 'Creating custom commands with VBA and UI Controls'
Code: 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