Finding max value in Two dimensional array???
:wave: Hey everybody.....are we ready for the superbowl?
I am working on a project where I have multiple tow dimensional arrays. I am trying to find the max value in the first "column" of my array. I have searched the net but I have only found ways to find the max values in a one dimensional array......can anyone help?
Re: Finding max value in Two dimensional array???
Is this what your looking for?
VB Code:
Dim aryString(15, 30) As String
aryString.GetUpperBound(0) 'Would return a value of 15
aryString.GetUpperBound(1) 'Would return a value of 30
Re: Finding max value in Two dimensional array???
Correct me if i'm wrong, but doesn't .GetUpperBound(0) return the last element in the array???
Re: Finding max value in Two dimensional array???
No... My array is as follows;
Dim Array1(,) As Double
ReDim Array1(30, 2)
The data in the array would look like this:
(0,0) = -36.5
(0,1) = 12
(0,2) = 6
(1,0) = -37.9
(1,1) = 9
(1,2) = 7
and so on.
I want to find the position of the max value in the first "column". For example the max of (0,0) -36.5 and (1,0)-37.9. In this case the position would be (0,0).
Re: Finding max value in Two dimensional array???
I think he means the highest value within an array. A multi-dimension array does not have "columns" as you may think. It is actually a matrix, so you will have to permatate each item like so:
VB Code:
Dim intArray(10, 20) As Integer
Dim MeRandom As New Random
For intIndex As Integer = 0 To intArray.GetUpperBound(0)
For intInnnerIndex As Integer = 0 To intArray.GetUpperBound(1)
intArray(intIndex, intInnnerIndex) = MeRandom.Next
Next
Next
Dim intFoundOutter As Integer
Dim intFoundInner As Integer
Dim intCurrentHighestValue As Integer = -1
'Check through the entire set to find the highest value
For intIndex As Integer = 0 To intArray.GetUpperBound(0)
For intInnnerIndex As Integer = 0 To intArray.GetUpperBound(1)
If intArray(intIndex, intInnnerIndex) > intCurrentHighestValue Then
intCurrentHighestValue = intArray(intIndex, intInnnerIndex)
intFoundOutter = intIndex
intFoundInner = intInnnerIndex
End If
Next
Next
MessageBox.Show("Found highest number of " & intCurrentHighestValue.ToString & " at (" & intFoundOutter.ToString & "," & intFoundInner.ToString & ")")
Re: Finding max value in Two dimensional array???
Thanks a lot.... I am up and running now. :thumb: