Results 1 to 4 of 4

Thread: Max Value in an Array

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2000
    Posts
    2

    Red face

    If you have an array of numbers is there any command that returns the greatest value in the array?

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Ubound(arrayname) returns upper bound
    Lbound(arrayname) returns lower bound
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  3. #3
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523
    FOr me your question says: how to find the greatest number in an array not the number of items in an array. If that the case then something like this would do it:
    Code:
    Option Explicit
    
    Private Sub Form_Load()
        Dim MyArray(1 To 6) As Integer
        Dim I As Integer
        Dim Temp As Integer
        
        For I = 1 To 6
            MyArray(I) = I
            If I = 6 Then
                MyArray(I) = 34
            End If
        Next I
        
        Temp = MyArray(1)
        For I = 2 To UBound(MyArray)
            If Temp < MyArray(I) Then
                Temp = MyArray(I)
            End If
        Next I
        
        MsgBox Temp '//Returns 34
    End Sub

  4. #4
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Nothing to stop you from writing your own

    dim i as int
    dim max_value as long 'or whatver the array value is defined

    max_value=0
    for i=1 to ubound(array_num)
    if array_num(i) > max_value then max_value=array_num(i)
    next i


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