HOW TO

Display table statistics in a new DBF table

Last Published: April 25, 2020

Summary

This article provides an Avenue example of how to retrieve statistics for all numeric fields in a table and display them in a new DBF table.

Procedure



  1. Open a new script window.

    A. Activate the Project window.
    B. Click the Scripts icon.
    C. Click New.

  2. Copy the following script:

    Code:
    RESULTFILE = FILEDIALOG.PUT("result.dbf".ASFILENAME,"*.*","FILE")
    RESULTVTAB = VTAB.MAKENEW(RESULTFILE,DBASE)
    RESULTTABLE = TABLE.MAKE(RESULTVTAB)
    F1 = FIELD.MAKE("FIELD_NAME",#FIELD_CHAR,12,0)
    F2 = FIELD.MAKE("Sum",#FIELD_DOUBLE,12,5)
    F3 = FIELD.MAKE("Count",#FIELD_DOUBLE,10,0)
    F4 = FIELD.MAKE("Mean",#FIELD_DOUBLE,10,5)
    F5 = FIELD.MAKE("Maximum",#FIELD_DOUBLE,10,5)
    F6 = FIELD.MAKE("Minimum",#FIELD_DOUBLE,10,5)
    F7 = FIELD.MAKE("Range",#FIELD_DOUBLE,10,5)
    F8 = FIELD.MAKE("Variance",#FIELD_DOUBLE,12,5)
    F9 = FIELD.MAKE("Standard Deviation",#FIELD_DOUBLE,10,5)
    RESULTVTAB.ADDFIELDS({F1,F2,F3,F4,F5,F6,F7,F8,F9})
    theTable = av.GetActiveDoc
    theVTab = theTable.GetVTab
    THEFIELDLIST = THEVTAB.GETFIELDS
    for each THEFIELD in THEFIELDLIST
    FIELDTYPE = THEFIELD.GETTYPE
    if ((FIELDTYPE = #FIELD_DECIMAL) or
    (FIELDTYPE = #FIELD_BYTE) or
    (FIELDTYPE = #FIELD_DOUBLE) or
    (FIELDTYPE = #FIELD_FLOAT) or
    (FIELDTYPE = #FIELD_LONG) or
    (FIELDTYPE = #FIELD_MONEY) or
    (FIELDTYPE = #FIELD_SHORT)) then
    thePrecision = "d.dddddddddd"
    theFieldPrecision = theField.GetPrecision
    Script.The.SetNumberFormat( thePrecision.Left( theFieldPrecision + 2 ) )
    if ( theVTab.GetSelection.Count = 0 ) then
    theSet = theVTab
    else
    theSet = theVTab.GetSelection
    end
    theSum = 0
    theCount = 0
    theMinimum = nil
    theMaximum = nil
    for each rec in theSet
    theValue = theVTab.ReturnValueNumber( theField, rec )
    if ( not ( theValue.IsNull ) ) then
    if ( theMinimum = nil ) then
    theMinimum = theValue
    theMaximum = theValue
    else
    theMinimum = theMinimum min theValue
    theMaximum = theMaximum max theValue
    end
    theSum = theValue + theSum
    theCount = theCount + 1
    end
    end
    theMean = theSum / theCount
    theSumSqDev = 0
    for each rec in theSet
    theValue = theVTab.ReturnValueNumber( theField, rec )
    if ( not ( theValue.IsNull ) ) then
    theSqDev = ( theValue - theMean ) * ( theValue - theMean )
    theSumSqDev = theSqDev + theSumSqDev
    end
    end
    if (theCount > 1) then
    theVariance = theSumsqdev / (theCount - 1)
    theStdDev = theVariance.Sqrt
    else
    theVariance = 0
    theStdDev = 0
    end
    REC = RESULTVTAB.ADDRECORD
    RESULTVTAB.SETVALUE(F1,REC,THEFIELD.GETNAME)
    RESULTVTAB.SETVALUE(F2,REC,THESUM)
    RESULTVTAB.SETVALUE(F3,REC,THECOUNT)
    RESULTVTAB.SETVALUE(F4,REC,THEMEAN)
    RESULTVTAB.SETVALUE(F5,REC,THEMAXIMUM)
    RESULTVTAB.SETVALUE(F6,REC,THEMINIMUM)
    RESULTVTAB.SETVALUE(F7,REC,(THEMAXIMUM - THEMINIMUM))
    RESULTVTAB.SETVALUE(F8,REC,THEVARIANCE)
    RESULTVTAB.SETVALUE(F9,REC,THESTDDEV)
    end
    end
    RESULTTABLE.SETNAME(RESULTFILE.GETBASENAME)
    RESULTTABLE.GETWIN.OPEN

  3. Attach the script to a button on the Table GUI.

    A. Compile the script.
    B. Switch to the Project window.
    C. Select Customize from the Project menu.
    D. Select Table under the Type dropdown on the Customize dialog.
    E. Select Buttons under Category.
    F. Click the New button.
    G. Double-click the Click property in the Customize dialog box.
    H. Enter the name of the script in the Script Manager and click Select.
    I. Close the Customize dialog box.

    For more information, see 'Customize dialog box' in ArcView Help.

  4. Load a table into ArcView.
  5. Click the newly added button.
  6. Specify a name and location for the DBF table.
  7. View results in the table.

Article ID:000004024

Software:
  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Discover more on this topic