sumcolumn Method
Class: tsgrid
Expand/Collapse source code of procedure sumcolumn Source Code
*-- (c) Microsoft Corporation 1995

*-- This method is used to sum a column in the grid and
*-- store the result to a custom property. Currently this
*-- works for only one column at a time.

IF EMPTY(this.cFieldToSum)
  RETURN
ENDIF

LOCAL lnOldArea, ;
    lnOldRecNo, ;
    luKey, ;
    lcFieldToSum, ;
    lcOrder

lnOldArea = SELECT()
this.nColumnSum = 0
lcFieldToSum = ""

IF EMPTY(this.RecordSource)
  RETURN
ENDIF

*-- Select the alias specified in the grid's RecordSource property
SELECT (this.RecordSource)

lcOrder = ORDER()
*-- Use the string returned by ORDER() as the parameter
*-- to the EVAL() function to retrive the value of the 
*-- current ID, which we use later to SEEK() into the table.
luKey = IIF(!EMPTY(lcOrder), EVAL(lcOrder), "")
lnOldRecNo = IIF(EOF(), 0, RECNO())
lcFieldToSum = this.cFieldToSum

*-- Total up the column and store the result 
*-- in the nColumnSum property
IF !EMPTY(lcOrder) AND SEEK(luKey)
  SUM &lcFieldToSum. ;
    WHILE luKey = EVAL(lcOrder) ;
    TO this.nColumnSum
ELSE
  IF CURSORGETPROP("SOURCETYPE") = DB_SRCLOCALVIEW OR ;
      CURSORGETPROP("SOURCETYPE") = DB_SRCREMOTEVIEW
    *-- Grid is bound to a view
    SUM &lcFieldToSum. ;
      TO this.nColumnSum
  ENDIF
ENDIF

IF lnOldRecNo <> 0
  GO lnOldRecNo
ENDIF

SELECT (lnOldArea)