*************************************************************************** * Description.......: GetMedianValue - returns median value from a specified table * Calling Samples...: GetMedianValue('curPrice','LstSlPrice') * Parameter List....: pcTableName, pcField * Created by........: Daniel Rouleau #025397 * Modified by.......: Nadya Nosonovsky 10/25/2000 11:43:05 AM ***************************************************************************** * Returns median value or .f. for unsuccessful cases lparameters pcTableName, pcField local lnMiddleRecord * pcTableName - name of the table or already opened cursor, which should be processed * pcFiled - name of the field, which used in calculation, price, for example * Both parameters are optional, if they are not specified, current working alias is used and price field lnOldSelect=select() && Save current area llCloseDBF=.f. if empty(pcField) or vartype(pcField)<>'C' pcField=upper('price') else pcField=upper(pcField) endif if empty(pcTableName) or vartype(pcTableName)<>'C' pcTableName=alias() && Current open alias if empty(pcTableName) && No current table return .f. endif endif release aResult select &pcField from (pcTableName) into array aResult order by 1 if _tally>3 lnMiddleRecord=ceiling(_tally/2) else =messagebox('Number of records is less than 3. Can not calculate median...',48) return .f. endif return aResult[lnMiddleRecord]>Nadya: