Monday, August 29, 2011

How do I sort arrays items using vbscript?

we will be able to sort in alphabetically an array items using the vbscript.

' declaring the array
Dim arrSortOut(10)
' assigning data to the array
arrSortOut(0)="Ammu"
arrSortOut(1)="Siva"
arrSortOut(2)="Madhu"
arrSortOut(3)="Ranga"
arrSortOut(4)="Jagadesh"
arrSortOut(5)="Kumar"
arrSortOut(6)="Praveen"
arrSortOut(7)="Martha"
arrSortOut(8)="Zeebra"
arrSortOut(9)="123Zeebra"
arrSortOut(10)="!123Zeebra"

for i = UBound(arrSortOut) - 1 To 0 Step -1
  for j= 0 to i
    if arrSortOut(j)>arrSortOut(j+1) then
      temp=arrSortOut(j+1)
      arrSortOut(j+1)=arrSortOut(j)
      arrSortOut(j)=temp
   end if
  next
next


for x=0 to 8 UBound(arrSortOut)
 msgbox arrSortOut(x)' to check the items
next