Micro Focus QTP (UFT) Forums
Sorting alphabetically - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: VB Scripting/Descriptive Programming (https://www.learnqtp.com/forums/Forum-VB-Scripting-Descriptive-Programming)
+--- Thread: Sorting alphabetically (/Thread-Sorting-alphabetically)



Sorting alphabetically - rachnamalik - 11-06-2014

I have a web table which has a column 'Member Name' and I would like to sort the table data in Asc and Desc when I click the column name.
How can I sort the data by member name, It would be great if someone can give inputs here.

Thanks


RE: Sorting alphabetically - supputuri - 11-08-2014

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.


RE: Sorting alphabetically - rachnamalik - 11-08-2014

Hi There,
Thanks for the detailed explanation. I have never used array either so how do we store the values in the array, wanted to know that too.

Thanks
Rachna