Results 1 to 6 of 6

Thread: Finding max value in Two dimensional array???

  1. #1

    Thread Starter
    Junior Member w8taminute's Avatar
    Join Date
    Aug 2006
    Posts
    24

    Finding max value in Two dimensional array???

    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?

  2. #2
    Hyperactive Member ProphetBeal's Avatar
    Join Date
    Aug 2006
    Location
    New York
    Posts
    424

    Re: Finding max value in Two dimensional array???

    Is this what your looking for?
    VB Code:
    1. Dim aryString(15, 30) As String
    2. aryString.GetUpperBound(0) 'Would return a value of 15
    3. aryString.GetUpperBound(1) 'Would return a value of 30

  3. #3
    Fanatic Member
    Join Date
    Aug 2006
    Posts
    734

    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???
    If your problem has been solved then please mark the thread [RESOLVED].
    If i have helped then please Rate my post

  4. #4

    Thread Starter
    Junior Member w8taminute's Avatar
    Join Date
    Aug 2006
    Posts
    24

    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).

  5. #5
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    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:
    1. Dim intArray(10, 20) As Integer
    2.         Dim MeRandom As New Random
    3.  
    4.         For intIndex As Integer = 0 To intArray.GetUpperBound(0)
    5.             For intInnnerIndex As Integer = 0 To intArray.GetUpperBound(1)
    6.                 intArray(intIndex, intInnnerIndex) = MeRandom.Next
    7.             Next
    8.         Next
    9.  
    10.         Dim intFoundOutter As Integer
    11.         Dim intFoundInner As Integer
    12.         Dim intCurrentHighestValue As Integer = -1
    13.  
    14.         'Check through the entire set to find the highest value
    15.         For intIndex As Integer = 0 To intArray.GetUpperBound(0)
    16.             For intInnnerIndex As Integer = 0 To intArray.GetUpperBound(1)
    17.                 If intArray(intIndex, intInnnerIndex) > intCurrentHighestValue Then
    18.                     intCurrentHighestValue = intArray(intIndex, intInnnerIndex)
    19.                     intFoundOutter = intIndex
    20.                     intFoundInner = intInnnerIndex
    21.                 End If
    22.             Next
    23.         Next
    24.  
    25.         MessageBox.Show("Found highest number of " & intCurrentHighestValue.ToString & " at (" & intFoundOutter.ToString & "," & intFoundInner.ToString & ")")

  6. #6

    Thread Starter
    Junior Member w8taminute's Avatar
    Join Date
    Aug 2006
    Posts
    24

    Re: Finding max value in Two dimensional array???

    Thanks a lot.... I am up and running now.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width