Function DDMax(ParamArray A() As Variant) As Single
'示例:select *,DDmax(字段1,字段2,字段3,字段4) as 最大值 from 表1
Dim i As Long
Dim Mx As Single
Mx = -1 * 10 ^ 10
For i = 0 To UBound(A, 1)
If IsNumeric(A(i)) = True Then
If A(i) > Mx Then Mx = A(i)
End If
Next
DDMax = Mx
End Function
Function DDMin(ParamArray A() As Variant) As Single
'示例:select *,DDmin(字段1,字段2,字段3,字段4) as 最小值 from 表1
Dim i As Long
Dim Mn As Single
Mn = 10 ^ 10
For i = 0 To UBound(A, 1)
If IsNumeric(A(i)) = True Then
If A(i) < Mx Then Mx = A(i)
End If
Next
DDMin = Mn
End Function
Function DDAvg(ParamArray A() As Variant) As Single
'示例:select *,DDAvg(字段1,字段2,字段3,字段4) as 平均值 from 表1
Dim i As Long
Dim S As Single
Dim C As Long
S = 0: C = 0
For i = 0 To UBound(A, 1)
If IsNumeric(A(i)) = True Then
S = S + A(i)
C = C + 1
End If
Next
If C <> 0 Then
DDAvg = S / C
Else
DDAvg = 0
End If
End Function
将以上代码拷贝到一个模块中,然后在查询中使用对应函数,比如求最大值:
SELECT *,Format(DDmax(E11,E12,E13,E21,E22,E23,E31,E32,E33),"0.000") AS 最大值
FROM 记录准确度记录表;
调试成功了,谢谢老师!
总记录:4篇 页次:1/1 9 1 :