Access中没有max(x,y)函数 [英] No max(x,y) function in Access
问题描述
Access的VBA缺少简单的Max(x,y)
函数来查找两个或多个值的数学最大值.我已经习惯了在基本API中已经有来自其他语言(例如perl/php/ruby/python等)的此类功能.
VBA for Access lacks a simple Max(x,y)
function to find the mathematical maximum of two or more values. I'm accustomed to having such a function already in the base API coming from other languages such as perl/php/ruby/python etc.
我知道可以做到:IIf(x > y, x,y)
.还有其他解决方案吗?
I know it can be done: IIf(x > y, x,y)
. Are there any other solutions available?
推荐答案
我将问题解释为:
如何在Access中实现返回数字数组的最大值/最小值的功能?这是我使用的代码(类似于IIf,名为"iMax",即"Immediate If"/"Immediate Max"):
How does one implement a function in Access that returns the Max/Min of an array of numbers? Here's the code I use (named "iMax" by analogy with IIf, i.e., "Immediate If"/"Immediate Max"):
Public Function iMax(ParamArray p()) As Variant
' Idea from Trevor Best in Usenet MessageID rib5dv45ko62adf2v0d1cot4kiu5t8mbdp@4ax.com
Dim i As Long
Dim v As Variant
v = p(LBound(p))
For i = LBound(p) + 1 To UBound(p)
If v < p(i) Then
v = p(i)
End If
Next
iMax = v
End Function
Public Function iMin(ParamArray p()) As Variant
' Idea from Trevor Best in Usenet MessageID rib5dv45ko62adf2v0d1cot4kiu5t8mbdp@4ax.com
Dim i As Long
Dim v As Variant
v = p(LBound(p))
For i = LBound(p) + 1 To UBound(p)
If v > p(i) Then
v = p(i)
End If
Next
iMin = v
End Function
在我看来,为什么Access无法实现它,这不是很常见的事情.它也不是很数据库".您已经拥有在整个域和行集中查找最大值/最小值所需的所有功能.实施也不难,也可以仅在需要时将其编写为一次性比较.
As to why Access wouldn't implement it, it's not a very common thing to need, seems to me. It's not very "databasy", either. You've already got all the functions you need for finding Max/Min across domain and in sets of rows. It's also not very hard to implement, or to just code as a one-time comparison when you need it.
也许以上内容对某人有帮助.
Maybe the above will help somebody.
这篇关于Access中没有max(x,y)函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!