4 Replies - 538 Views - Last Post: 27 October 2016 - 10:50 PM Rate Topic: -----

#1 CarolinaN  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-October 16

Finding the highest value in an array row & returning column num.

Posted 27 October 2016 - 01:10 PM

The title basically explains it, but here we go:

I have an array with 26 columns and 2 rows. The first row contains the values 65 - 90 in ascending order. The second row will contain a range of numbers. I need to find the highest value in the second row and return the column number. Any help on how to do this? I've looked at some example code, but I can only find 1 dimensional arrays for max values.

In case it would help, here is my code:

(Ciphertext isn't currently there, but it would just be a piece of text)
Module Module1

    Sub Main()
        Dim num As Integer
        'Ciphertext goes between the two speech marks next line
        Dim ciphertext As String = UCase("")
        Dim array(25, 2) As Integer
        For a = 1 To 26
            array(a - 1, 0) = a + 64
            array(a - 1, 1) = 0
        Next

        For b = 0 To ciphertext.Length
            num = Asc(ciphertext.Substring(b, 1))
            Select Case num
                Case 65 To 90
                    array(num, 1) = array(num, 1) + 1
            End Select
        Next


    End Sub

End Module



Is This A Good Question/Topic? 0
  • +

Replies To: Finding the highest value in an array row & returning column num.

#2 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: Finding the highest value in an array row & returning column num.

Posted 27 October 2016 - 01:24 PM

not sure why you require the first row? it just has the values 65, 66, 67 .... etc
once you find the maximum in the second row the value of the first row would be column+65?
Was This Post Helpful? 0
  • +
  • -

#3 CarolinaN  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 01-October 16

Re: Finding the highest value in an array row & returning column num.

Posted 27 October 2016 - 01:46 PM

K, sorry if I'm just being dumb at this point. I modified the code so it's just one row, how do I then find which column it is in? I'm sure I'm just missing a function, but so far my efforts are not really doing much.
Was This Post Helpful? 0
  • +
  • -

#4 horace  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 768
  • View blog
  • Posts: 3,832
  • Joined: 25-October 06

Re: Finding the highest value in an array row & returning column num.

Posted 27 October 2016 - 10:16 PM

if you do a web search for "vb.net array maximum" you will find many links, e.g.
http://www.freevbcod...ode.asp?ID=8459
https://www.dotnetpe...h-max-min-vbnet
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw  Icon User is offline

  • blow up my boots
  • member icon

Reputation: 6541
  • View blog
  • Posts: 26,474
  • Joined: 12-December 12

Re: Finding the highest value in an array row & returning column num.

Posted 27 October 2016 - 10:50 PM

If you are using a variable x to loop through and find the largest number then, when you encounter this largest number, make a note of (store) the x-value where the number occurred. If you find a bigger number, store its x-value instead. Once you've completed the loop x will tell you where the biggest number lives. x marks the spot.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1