Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sorting alphabetically
#2
Solved: 7 Years, 9 Months ago
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.
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
Reply


Messages In This Thread
Sorting alphabetically - by rachnamalik - 11-06-2014, 11:40 PM
RE: Sorting alphabetically - by supputuri - 11-08-2014, 12:11 AM
RE: Sorting alphabetically - by rachnamalik - 11-08-2014, 12:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  program for sorting aparna_baishya 2 2,763 05-11-2008, 05:41 AM
Last Post: Anshoo Arora

Forum Jump:


Users browsing this thread: 1 Guest(s)