shannon56

Get Selected Values for Statistics

Discussion created by shannon56 on Jun 13, 2011
Latest reply on Jun 20, 2011 by Dan_Patterson
Hi,
I'm using the following code in VBA to get statistics on a field and show it in a form.  Can someone help me with getting the statistics for only the selected features?

Thanks!

Dim pMxDoc As esriArcMapUI.IMxDocument, pFLayer As esriCarto.IFeatureLayer, pData As esriGeoDatabase.IDataStatistics
  Dim pCursor As esriGeoDatabase.ICursor, pStatResults As esriSystem.IStatisticsResults
  Dim pfeatureselection As IFeatureSelection
    
  Set pMxDoc = ThisDocument
  Set pFLayer = pMxDoc.FocusMap.Layer(0)
  Set pCursor = pFLayer.Search(Nothing, False)
 
  'Statistics for Condition
  Set pData = New esriGeoDatabase.DataStatistics
  pData.Field = "ConditionRating"
  Set pData.Cursor = pCursor
  Set pStatResults = pData.Statistics
 
  Dim mean As Double
  Dim count As Integer
  mean = Format(pStatResults.mean, "000000.00")
  count = pStatResults.count
 
  'Show Values in form
  frmTest.txtTest.value = mean
  frmTest.txtCount = count

Outcomes