WORKING WITH QTP

TestEveryThinG

Sorting of Array by using VB script

Posted by rajivkumarnandvani on December 31, 2010

HAPPY NEW YEAR :)

Hi All ,

Sometimes while doing scripting we required sorting of array number. Here I am posting the script that will sort the number of array.

arrSample = Array(4, 6, 2, 7, 3, 5, 1)

msgbox vbCrLf & “array before”

For Each intNumber In arrSample

msgbox intNumber

Next

Function SortArray (byval arrayname)

For i = LBound(arrayname)  to  UBound(arrayname)

For j = LBound(arrayname)  to  UBound(arrayname)

If j <> UBound(arrayname)  Then

If arrayname(j) > arrayname(j + 1)  Then

TempValue = arrayname(j + 1)

arrayname(j + 1) = arrayname(j)

arrayname(j) = TempValue

End If

End If

Next

Next

SortArray = arrayname

End Function

msgbox vbCrLf & “array after”

REM calling function SortArray()

Arrayaftersort  =  SortArray(arrSample)

For Each intNumber  In Arrayaftersort

msgbox intNumber

Next

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
Follow

Get every new post delivered to your Inbox.

Join 153 other followers

%d bloggers like this: