Russian version
English version
| | | | SILICON TAIGA | ISDEF | CD | | | | | | | |
 
 
 
IT-
 
 
 
RSS-

osmor

.
DCount, DMax ..
OptionCompareDatabase
OptionExplicit

PublicFunctionDMedian(strNameFielsAsString,strNameTBLAsString,OptionalstrFilterAsString="")AsVariant
':osmor27.11.2006.
'
'DCount,DMax..
'strNameFiels-
'strNameTBL-
'strFilter-
DimdblrezAsDouble
DimrstAsADODB.Recordset
DimlngCountAsLong
DimlngTempAsDouble
OnErrorGoToErr_dMedian

lngCount=Nz(DCount("*",strNameTBL,strFilter),0)
IflngCount=0ThenDMedian=Null:ExitFunction
Setrst=NewADODB.Recordset
rst.Open"select"&strNameFiels&"from"&strNameTBL&IIf(strFilter="","","where"&strFilter)&"orderby"&strNameFiels,CurrentProject.Connection,adOpenKeyset,adLockReadOnly
If(lngCountMod2)=1Then
rst.AbsolutePosition=CLng(lngCount\2)+1
dblrez=Nz(rst.Fields(0),0)
Else
rst.AbsolutePosition=CLng(lngCount\2)
lngTemp=Nz(rst.Fields(0),0)
rst.MoveNext
dblrez=(lngTemp+Nz(rst.Fields(0),0))/2
EndIf
Setrst=Nothing
DMedian=dblrez
Exit_dMedian:
ExitFunction

Err_dMedian:
SelectCaseErr.Number
CaseElse
MsgBox"("&Err.Number&")"&Err.Description&"dMedian"
ResumeExit_dMedian
EndSelect

EndFunction


     
 
 
  : 19.07.2006  

| | | | SILICON TAIGA | ISDEF | CD | | | | | | | |

: Silicon Taiga    
Rambler's Top100 Rambler's Top100