Wednesday, March 21, 2007

Sorting Arrays in VBScript - Part 2

Yesterday, I included a function to sort an array of numbers or strings. The following is a minor spin on that function, sorting an array of OBJECTS by their .name attribute. Pretty much all Microsoft-related objects have this name attribute. So you could sort an array of website objects, virtual directory objects, file objects, etc.

Hope this helps somebody!


'******************************************************************************************
' SortObjectArrayByName - sort an array of objects by their name attributes
' arrObj - incoming array of unsorted objects
'******************************************************************************************
function SortObjectArrayByName(arrObj)
dim i, j, temp
dim name0, name1, obj

for i = UBound(arrObj) - 1 To 0 Step -1
for j= 0 to i
set obj = arrObj(j)
name0 = obj.name
set obj = arrObj(j+1)
name1 = obj.Name
if name0 > name1 then
set temp = arrObj(j+1)
set arrObj(j+1) = arrObj(j)
set arrObj(j) = temp
end if
next
next
SortObjectArrayByName = arrObj
end function

4 comments:

Anonymous said...

You are going to create a new partition in the free space on your hard-drive.

If you do not have any suggestions what Facebook lovers are then do
not fear whatsoever.

Stop by my homepage: kik for pc (http://www.chaddibaddi.com/index.php?do=/profile-18810/info/)

Anonymous said...

Thanks very interesting blog!

Feel free to surf to my weblog :: www.keydesignwebsites.com

Anonymous said...

Great beat ! I would like to apprentice whilst you amend
your web site, how can i subscribe for a blog web site?
The account aided me a acceptable deal.
I had been tiny bit acquainted of this your broadcast provided bright clear idea

my homepage เบอร์สวย

Anonymous said...

smokeless cigarettes, electronic cigarette starter kit, electronic cigarettes reviews, ecigs, buy electronic cigarette, electronic cigarette brands