If you have an array of numbers is there any command that returns the greatest value in the array?
Printable View
If you have an array of numbers is there any command that returns the greatest value in the array?
Ubound(arrayname) returns upper bound
Lbound(arrayname) returns lower bound
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
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