RGB,
You'd have to loop through the entire thing assigning each value to a variable if it's higher that what's currently in the variable (which would be intitialized to whatever the lowest possible value is for that data type). A standard array has no instrisnic Max() function, and if it did, that function would still be doing a full scan.
--jsteph
You would probably use a for-next loop to run a single element of an array to find the highest value. For a 4 dimensional array that you're using it would require nested for-next loops. The seems to be a lousy approach to the problem. Why not just establish four global values to hold the array location of the highest value in each array element at the outset? Then, each time a value is written to the array, test it against the max value for that element and decide whether the new value is higher than the max recorded value in the array. Keeping a running list of the highest (or lowest) values seems a more efficient method to me than searching an entire array.
----------------------------------------------------
Function aMax(ParamArray arr() As Variant)
' return max value of n..m passed
' example : foo = aMax(1,17,6,34,199,0,2)
' foo = 199
Dim i As Integer, temp As Integer
temp = arr(UBound(arr))
For i = LBound(arr) To UBound(arr)
If arr(i) > temp Then
temp = arr(i)
End If
Next i
aMax = temp
End Function
------------------------------------------ Me? Ambivalent? Well, yes and no....
Another free Access forum:
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.