Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Max Value in an array

Status
Not open for further replies.

rgbanse

MIS
Jun 4, 2001
211
US
how do I determine the max value in an array
thx
RGB
 
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
 
jsteph,
this is my first effort with an array

DemandSet = Array(OrdValue, EdiValue, FcaValue, SspValue)

I'm totally lost as to how I 'Loop' through the array to determine min or max.
thx
RGB
 
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.
 
Try this:

----------------------------------------------------
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:
More Access stuff at
 
AvGuy, that's not a 4-dimensional array. It's a
one-dimensional array with 4 elements.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top