Friday, February 25, 2011

Sort the Array elements

Whith below code we can sort the Array values

Dim arrSortOut(8)
arrSortOut(0)=2
arrSortOut(1)=1
arrSortOut(2)=5
arrSortOut(3)=6
arrSortOut(4)=8
arrSortOut(5)=0
arrSortOut(6)=9
arrSortOut(7)=3
arrSortOut(8)=4


For i = UBound(arrSortOut) - 1 To 0 Step -1
For j= 0 to i
' you want in Ascending order
If arrSortOut(j)>arrSortOut(j+1) then
' You want in Decending order
' if arrSortOut(j) temp=arrSortOut(j+1)
arrSortOut(j+1)=arrSortOut(j)
arrSortOut(j)=temp
end if
Next
Next


For x=0 to 8
msgbox arrSortOut(x)
Next