Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a combobox that shows all fields of a shapefile.

I want to get these values programmatically in a label--Count, Minimum, Maximum, Sum, Mean, Standard Deviation--and populate a graph of the selectable fields in the combobox. All that in the same form.

Please could anyone help me :(

share|improve this question
How will you get these values in a label...can you please explain? Do you want separate labels for each? What about the axis information about the graph...? – ujjwalesri Jun 14 '11 at 10:50


Example here:

share|improve this answer
thank u for the answer but it doesn't work – Sara Jun 19 '11 at 21:13
What exactly doesn't work? Can you be more specific? IDataStatistics:Statistics (IStatisticsResults) will provide you with the required field statistics. – Jakub Jun 19 '11 at 21:56
it work, i re try it it works know, but sometimes it give an error and close all arcgis opened files.. – Sara Jun 20 '11 at 15:17
i did some changes, that's the code i wrote : – Sara Jun 20 '11 at 15:17
here is the message error : Erreur d'exécution '-2147417848(80010108)' Erreur Automation L'objet invoqué s'est déconnecté de ses clients – Sara Jun 20 '11 at 15:45

Thank u Jakub, it work, but sometimes it give an error that close all the arcgis opened windows

i did some changes to the code this is my code

 Private Sub CmboFld_Change()

Dim pMxDoc As esriArcMapUI.IMxDocument, pFLayer As esriCarto.IFeatureLayer, pData As esriGeoDatabase.IDataStatistics Dim pCursor As esriGeoDatabase.ICursor, pStatResults As esriSystem.IStatisticsResults Set pMxDoc = ThisDocument Set pFLayer = pMxDoc.FocusMap.Layer(0) Set pCursor = pFLayer.Search(Nothing, False)

Set pData = New esriGeoDatabase.DataStatistics pData.Field = CmboFld.Text Set pData.Cursor = pCursor

Dim pEnumVar As esriSystem.IEnumVariantSimple, value As Variant Set pEnumVar = pData.UniqueValues value = pEnumVar.Next

Set pCursor = pFLayer.Search(Nothing, False) Set pData.Cursor = pCursor Set pStatResults = pData.Statistics Txt1.Caption = pStatResults.Maximum Txt2.Caption = pStatResults.Minimum Txt3.Caption = pStatResults.Sum Txt4.Caption = pStatResults.Mean Txt5.Caption = pStatResults.StandardDeviation End Sub

and :

  Private Sub UserForm_Initialize()

'------------- Remplir la combobox------------------------------------ 'clear combobox CmboFld.Clear Dim i As Integer Dim pMxDoc As IMxDocument Set pMxDoc = ThisDocument Dim pFeatureLayer As IFeatureLayer Set pFeatureLayer = pMxDoc.FocusMap.Layer(0) '1st layer For i = 0 To pFeatureLayer.FeatureClass.Fields.FieldCount - 1 CmboFld.AddItem pFeatureLayer.FeatureClass.Fields.Field(i).Name Next i End Sub

it work, now i have a probleme, how to populate a graph, i did used this :

Private Sub Graph()
Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

' get the name of the layer containing feature points
Dim pLayer As ILayer
Set pLayer = pMxDoc.FocusMap.Layer(0)

' create graph
Dim pDataGraphBase As IDataGraphBase
Dim pDataGraphT As IDataGraphT
Set pDataGraphBase = New DataGraphT
Set pDataGraphT = pDataGraphBase

Dim layerName As String
layerName = pLayer.Name

' graph and legend titles
pDataGraphT.GeneralProperties.Title = "Graphe"
pDataGraphT.LegendProperties.Title = "Legende"
pDataGraphBase.Name = "Graphe représentant - " & layerName

' create vertical line series
Dim pSP As ISeriesProperties
Set pSP = pDataGraphT.AddSeries("line:vertical")
pSP.colorType = esriGraphColorMatch
pSP.WhereClause = "GAGE_NO_ = 2 AND YEAR_ = 99"
pSP.InLegend = True

pSP.SourceData = pLayer
pSP.SetField 0, "TSDateTime"
pSP.SetField 1, "TSValue"
Dim pSortFlds As IDataSortSeriesProperties
Set pSortFlds = pSP
Dim idx As Long
pSortFlds.AddSortingField "TSDateTime", True, idx

Dim pCancelTracker As ITrackCancel
Set pCancelTracker = New CancelTracker
pDataGraphT.Update pCancelTracker

' create data graph window within ArcMap
Dim pDGWin As IDataGraphWindow2
Set pDGWin = New DataGraphWindow
Set pDGWin.DataGraphBase = pDataGraphBase
Set pDGWin.Application = ThisDocument.Parent
pDGWin.Show (True)

Dim pDataGraphs As IDataGraphCollection
Set pDataGraphs = pMxDoc
pDataGraphs.AddDataGraph pDataGraphBase

    ' export the graph instead of displaying in ArcMap, use the following code,
    ' and comment the above 9 lines
    Dim fileName As String
    fileName = Form1.Dir & layerName & ".jpg"
    pDataGraphT.ExportToFile fileName

End Sub

Private Sub CmdGrph_Click() Graph End Sub

It give me an empty graph, with a text zone "There is no selection" when i double click at that zone text, it give me, graph propreities i choose this informations :

Graph Type: Vertical Bar

Layer/Table: pMxDoc.FocusMap.Layer(0)

Value Field: CmboFld.Text

then it populate the graph

I want to populate that Graph AUTOMATICALLY when i click at Graph Button

please could Anyone Helping me

share|improve this answer
instead of posting this new question as a answer to your original question you should either edit your original question or create a new question and make a reference to your prior question. – artwork21 Jun 20 '11 at 16:03
This appears to be "Automation error The object invoked has disconnected from its clients" In VBA the problem is sometimes linked to not explicitly releasing ArcObjects references. When no longer needed (especially in a loop) you should explicitly set the variable = Nothing. (for example set pDataStatistics = nothing, etc.) If you debug and step through the code line by line you should be able to isolate where exactly its crashing. – Jakub Jun 20 '11 at 16:44

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.