How to find max and min values in an array

1,776 views
Skip to first unread message

shalini reddy

unread,
Jan 24, 2011, 1:48:45 AM1/24/11
to mercu...@googlegroups.com
i have an array values as a(2,6,4,7)
how can i find the max and min values ,,,,


Regards
Shalini

ashok n

unread,
Jan 24, 2011, 2:10:57 AM1/24/11
to mercu...@googlegroups.com
u have to go for any sorting  orders then u can find out..
 
if you are not clear let me know..
 
i will update u the logic..
 
Regards
 
Ashok.N
CapGemini India Pvt Ltd

--
You received this message because you are subscribed to the Google
"QTP - HP Quick Test Professional - Automated Software Testing"
group.
To post to this group, send email to Mercu...@googlegroups.com
To unsubscribe from this group, send email to
MercuryQTP+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/MercuryQTP?hl=en



--
Cheers,

Ashok Kumar.N
+91 9711545679

Anoj Atapattu

unread,
Jan 24, 2011, 5:56:39 AM1/24/11
to mercu...@googlegroups.com
You can use this function to return the Max Value, Like wise you can update the function to return Min Value.

Function to Return Max Value in an Array
Public Function getArrMaxValueIndex(ByVal arr)
        Dim ix, ixMax
        ixMax = 0
        For ix = 1 To UBound(arr)
            If ( arr(ixMax) < arr(ix) ) Then
                ixMax = ix
            End If
        Next
        getArrMaxValueIndex = ixMax
End Function

'Define array and index for max entry
Dim arr, ixMax

'Initialize the array
arr = Array(4, 1, 3, 6, 7, 23,567,34,44)

'Get the index of the max value
ixMax = getArrMaxValueIndex(arr)

'Print result
MsgBox "Max value: " & arr(ixMax) & " was found at " & ixMax & " index."


Cheers,

Anoj Atapattu

Mr. Anand

unread,
Jan 24, 2011, 12:28:37 PM1/24/11
to QTP - HP Quick Test Professional - Automated Software Testing
I hope the below post shall help you on the same..
http://csesupport.blogspot.com/2010/11/related-posts-on-qtp-vbscript-functions.html

Do let me know in case I can help you more on the same..

Roman

unread,
Jan 27, 2011, 9:23:06 AM1/27/11
to QTP - HP Quick Test Professional - Automated Software Testing
How will that work if the array has 1 item (or 0 items)?
> > On Mon, Jan 24, 2011 at 12:18 PM, shalini reddy <shaliniredd...@gmail.com>wrote:
>
> >> i have an array values as a(2,6,4,7)
> >> how can i find the max and min values ,,,,
>
> >> Regards
> >> Shalini
>
> >> --
> >> You received this message because you are subscribed to the Google
> >> "QTP - HP Quick Test Professional - Automated Software Testing"
> >> group.
> >> To post to this group, send email to Mercu...@googlegroups.com
> >> To unsubscribe from this group, send email to
> >> MercuryQTP+...@googlegroups.com<MercuryQTP%2Bunsubscribe@googlegrou ps.com>
> >> For more options, visit this group at
> >>http://groups.google.com/group/MercuryQTP?hl=en
>
> > --
> > Cheers,
>
> > Ashok Kumar.N
> > +91 9711545679
>
> >  --
> > You received this message because you are subscribed to the Google
> > "QTP - HP Quick Test Professional - Automated Software Testing"
> > group.
> > To post to this group, send email to Mercu...@googlegroups.com
> > To unsubscribe from this group, send email to
> > MercuryQTP+...@googlegroups.com<MercuryQTP%2Bunsubscribe@googlegrou ps.com>
Reply all
Reply to author
Forward
0 new messages