Pages

Wednesday, March 2

Find the highest number in the array

'This code demonstrate how to find the highest number in a numaric array.
 
Dim num, i, Length1

num=array(34,12,98,43,89,49,56)
Length1 = UBound(num)    'Find the length of array

For i= 1 to Length1
 If (num(i) < num(0)) Then  'to find lowest number, just change it to >
    num(0)=num(i)
 End If
Next

MsgBox num(0) 'Highest Number

16 comments:

  1. thanks Abhikansh..
    keep it up!! :)

    ReplyDelete
  2. outstanding work....keep it up....

    ReplyDelete
  3. i tried to pass numbers(5,10,15) in array to find the biggest number and getting as 5. but it should be 15. pls help me in this.

    num=array("5","10","15")
    Length1 = UBound(num)
    For i= 1 to Length1
    If (num(i)>num(0)) Then
    num(0)=num(i)
    End If
    Next

    MsgBox num(0)

    ReplyDelete
  4. @raghav,

    plz dont use double qoutes while paasing values in array..

    ReplyDelete
  5. superb! whatever search here i can get solution here thanks dude

    ReplyDelete
  6. plz help me... how to capture screen shot during runtime... what is syntax and explain plz

    ReplyDelete
  7. @satish k

    plz search CaptureBitmap in qtp help

    ReplyDelete
  8. find the max value from array
    Dim x,y,max
    x=array(50,20,30,40,90)
    z=UBound(x)
    max=0
    For i = 0 To z
    If x(i)>max Then
    max=x(i)
    End If
    Next
    MsgBox max

    ReplyDelete
  9. Yo can try this one also:

    Dim a, temp, i, j, firsthighest, secondhighest, thirdhighest
    a = Array(35,44,99,66,98,76)
    'Sorting the array in Ascending order
    for i=0 to UBound(a)
    for j=0 to UBound(a)
    if (strcomp(a(i), a(j), 1)<0) then
    temp = a(i)
    a(i) = a(j)
    a(j) = temp
    end if
    Next
    Next

    firsthighest = (UBound(a))
    msgbox "First highest mark is: "&a(Firsthighest)

    secondhighest = (UBound(a)-1)
    msgbox "Second highest mark is: "&a(secondhighest)

    ReplyDelete
  10. I dint get these lines.....
    num(i) is actually an number or index? why for loop started from 1 rather 0
    For i= 1 to Length1
    If (num(i)>num(0)) Then
    num(0)=num(i)
    End If
    Next

    ReplyDelete
  11. The above code should be start little bit we need to correct
    For i = 0 to Length

    ReplyDelete
  12. How can i sort larger number to lowest? but user input the numbers in arry

    ReplyDelete