VBScript: Sort Array

Filed under: Quick Code, VBScript — Written by Chrissy on Friday, July 28th, 2006 @ 2:56 am

Found this code and wanted to bookmark it... from VisualBasicScript.com's Forums

Function fSortArray(aSortThisArray)
Set oArrayList = CreateObject("System.Collections.ArrayList" )
For iElement = 0 To UBound(aSortThisArray)
  oArrayList.Add aSortThisArray(iElement)
Next
oArrayList.Sort
set fSortArray = oArrayList
Set oArrayList = Nothing
End Function
6 Comments   -
  • Comment by spark86 | August 17, 2006 @ 10:12 am

    Just FYI this only works if you are useing a one d array

  • Comment by Arnaud | September 1, 2006 @ 8:48 am

    Dear Chrissy,

    Thanks a lot for this tip.
    I still use a standard sort code :( Now, my code will be more simple ;))

    MERCI

    Arnaud
    "French Wine is the blood of France"

  • Comment by DiGiTAL.SkReAM | October 4, 2006 @ 8:27 am

    Hey, kinda neat to search google, and find my code somewhere else! lol in any case, jsut watned to leave a warning that the System.Collections.ArrayList object can only be created if you .NET installed. On systems that haven't had that installed, it will error-out with a "Microsoft VBScript runtime error: ActiveX component can't create object: 'System.Collections.ArrayList'" error.

    Have a good one!
    DS

  • Comment by Giannis | January 31, 2007 @ 1:06 am

    Thanks, works perfect with Rational Clear Quest basic scripts.

  • Comment by not required | February 1, 2007 @ 5:41 pm

    you can drop the dictionary, just using memory...never used

  • Comment by abhishek | April 4, 2008 @ 12:06 pm

    I need to check the sorting of a table based on the column headers of a web table. Also, i can sort one column in ascending while the other column being in descending.
    Any solutions?

Leave your comment