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

6 comments:

Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa pages. Thank you So much.
Oes Tsetnoc | Semangat Mengembalikan Jati Diri Bangsa

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...

Greate pieces. Keep writing such kind of info on your page.
Im really impressed by your blog.
Hello there, You have done a great job. I'll definitely digg it
and for my part suggest to my friends. I am sure they will be
benefited from this website.

my weblog: dry carpet cleaners california

Anonymous said...

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