11-08-2014, 12:11 AM
Hi there are 2 ways you can do the sorting - before sorting store all the values into array and pass the array to either of the functions.
Second Way
Let me know if you need any more information on this.
Code:
Function SortAnArrary(aArrary,strSortingOrder)
for iCounter = UBound(aArrary) - 1 To 0 Step -1
for iInternalCounter= 0 to iCounter
if aArrary(iInternalCounter)>aArrary(iInternalCounter+1) then
buffer=aArrary(iInternalCounter+1)
aArrary(iInternalCounter+1)=aArrary(iInternalCounter)
aArrary(iInternalCounter)=buffer
end if
next
next
If lcase(strSortingOrder) = "ascending" Then
for iOutPutCounter=0 to UBound(aArrary)
sOutPut = sOutPut & "," & aArrary(iOutPutCounter)
next
ElseIf lcase(strSortingOrder) = "descending" Then
for iOutPutCounter= UBound(aArrary)-1 to 0 Step-1
sOutPut = sOutPut & "," & aArrary(iOutPutCounter)
next
End If
SortAnArrary = Mid(sOutPut,2,Len(sOutput))
End Function
Second Way
Code:
Function SortAnArray(aArray,strSortOrder)
Set ArrayList= CreateObject( "System.Collections.ArrayList" )
For i=0 to Ubound(aArray)-1
ArrayList.Add aArray(i)
Next
Rem Sorting array list
ArrayList.sort
If lcase(strSortOrder) = "ascending" Then
For i=0 to Ubound(aArray)-1
sOutPut = sOutPut & "," & ArrayList.item(i)
Next
ElseIf lcase(strSortOrder) = "descending" Then
For i= Ubound(aArray)-1 to 0 step -1
sOutPut = sOutPut& "," & ArrayList.item(i)
Next
End If
SortAnArray = Mid(sOutPut,2,Len(sOutPut))
Set ArrayList= Nothing
End Function
Let me know if you need any more information on this.
Thanks,
SUpputuri
SUpputuri