|
|
CODE ' Code courtesy of UtterAccess Wiki
' http://www.utteraccess.com/wiki/index.php/Category:FunctionLibrary ' Original submission by John White (jwhite) ' Date contributed: 2010/08/27 ' '================================================================================ 'NAME : GetMaxArrayValue 'PURPOSE : Returns the Maximum value of variables passed. Alleviates ' the need to compare variable values with lengthy code. 'RETURNS : Variant 'ARGUMENTS: Two or more variables or values, separated by comma's 'REFERENCE: http://msdn.microsoft.com/en-us/library/ct363x9h%28VS.80%29.aspx ' 'USAGE : In VBA Code: ' intMax = GetMaxArrayValue(intScore1, intScore2, intScore3) ' ' As Control Source for a Control: ' =GetMaxArrayValue([txtScore1], [txtScore2], [txtScore3]) '-------------------------------------------------------------------------------- Function GetMaxArrayValue(ParamArray varValues()) As Variant On Error GoTo GetMaxArrayValue_Error Dim intCounter As Integer For intCounter = 0 To UBound(varValues) If GetMaxArrayValue < varValues(intCounter) Or IsNull(GetMaxArrayValue) Then GetMaxArrayValue = varValues(intCounter) End If Next GetMaxArrayValue_Cleanup: Exit Function GetMaxArrayValue_Error: 'INSERT YOUR ERROR HANDLING CODE HERE Resume GetMaxArrayValue_Cleanup End Function The result of this function is not exact in this case : GetMaxArrayValue(Null,0) -> Null. I submit my function for this reason and because it is faster : CODE Public Function getMax(ParamArray pa() As Variant) As Variant Dim v As Variant For Each v In pa If getMax < v Then getMax = v ElseIf IsEmpty(getMax) And Not IsNull(v) Then getMax = v End If Next v End Function The same function to get the minimum : CODE Public Function getMin(ParamArray pa() As Variant) As Variant Dim v As Variant For Each v In pa If getMin > v Then getMin = v ElseIf IsEmpty(getMin) And Not IsNull(v) Then getMin = v End If Next v End Function
|
| This page was last modified 20:18, 19 March 2012. This page has been accessed 895 times. Disclaimers |