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
Showing posts with label Arrays. Show all posts
Showing posts with label Arrays. Show all posts
Wednesday, March 21, 2007
Subscribe to:
Posts (Atom)