More Really Useful VBScript Array Functions – ArraySort and DoubleArraySort

A while back I wrote an article about VBScript arrays and their various shortcomings entitled “VBScript Array Functions – DeleteFromArray, InArray”. I love these functions because they really simplify the manipulation of arrays and directly address some of the obvious flaws with the initial implementation of arrays in VBScript.

At the end of that article, written almost a year ago, I also mention writing sort functions for VBScript. Well I finally go around to it today and decided that these two functions were just way to handy not to share.

The first one, which will probably be the one most commonly used is a simple sort function, where you can sort ascendingly or descendingly depending on which value you pass for sOrder. The nice thing about this, is that it will sort your array simply by calling it as a normal sub.

The second sub works exactly like the first one, except that it will sort 2 arrays relationally. For example, lets say you have Array1 and Array2 who’s indexes are related. Lets say now you wish to sort Array1 but also maintain the 1:1 relationship you have between Array1 and Array2. This sub will do exactly that by passing Array1 as the first parameter, Array2 as the second parameter and the order, descending or ascending as the final parameter.

I think these are pretty slick and many of you will find them immensely useful in your own scripts and projects. As usual, I’d love to get any feedback so feel free to post below!

 

Leave a Comment