how to find second highest marks in an array using vb script

640 views
Skip to first unread message

Pradeep Reddy

unread,
Jan 23, 2014, 9:56:34 PM1/23/14
to mercu...@googlegroups.com
hi all qtp professionals this is pradeep....pls find out me the answer

Jeyaprakash R

unread,
Jan 24, 2014, 10:31:09 AM1/24/14
to mercu...@googlegroups.com
Hi Pradeep,

Here is the script.

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)

thirdhighest = (UBound(a)-2)
msgbox "Third highest mark is: "&a(thirdhighest)

Regards,
Jeyaprakash R


On Fri, Jan 24, 2014 at 8:26 AM, Pradeep Reddy <pradeepvedh...@gmail.com> wrote:
hi all qtp professionals this is pradeep....pls find out me the answer

--
--
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
 
---
You received this message because you are subscribed to the Google Groups "QTP - HP Quick Test Professional - Automated Software Testing" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mercuryqtp+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Nik

unread,
Jan 24, 2014, 4:03:50 PM1/24/14
to mercu...@googlegroups.com
My god, vbscript is such a pain sometimes!
I just use. Net object in this instance since im sure its intalled on your computer. Look how simple.

Set outputLines = CreateObject("System.Collections.ArrayList")

'add lines
outputLines.Add 9
outputLines.Add 5
outputLines.Add 3
outputLines.Add 0
outputLines.Add 50
outputLines.Add 3

outputLines.Sort()
For Each outputLine in outputLines
    'Display all of the elements
    'MsgBox outputLine
Next

MsgBox "Element #0 " & outputLines(0)
MsgBox "Element #1 " & outputLines(1)   'This is what you want, second element
www.qtptutorial.net
Reply all
Reply to author
Forward
0 new messages