Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

return sorted array?

Status
Not open for further replies.

cjkenworthy

Programmer
Sep 13, 2002
237
GB
I've found out that using Jscript's sorting algorithm can be faster than doing a bubble sort so am using the following code. However it is not generating a sorted array. I want it to overwrite my unsorted array and return it sorted (the array is called 'SoftwareUsers') :

<script language=JScript runat=server>
function SortVBArray(arrVBArray) {
return arrVBArray.toArray().sort().join('\b');
}
</script>
<%
Function SortArray(arrInput)
SortArray = Split(SortVBArray(arrInput), Chr(8))
End Function

SortArray(SoftwareUsers)

'This remains unsorted when outputted...
for i=0 to UBound(arrInput)
response.write(arrInput(i) & "<br>")
next
%>
 
On a cursory glance, all I can say is that typically, when you use a function , you need to set it equal to a variable. I.E. the line:

SortArray(SoftwareUsers)

should probably be something like

SoftwareUsers = SortArray(SoftwareUsers)

Then the code following should be looking at the softwareusers array, rather than the array variable being used within the SortArray function. So I would typically follow the line above with

for i=0 to UBound(SoftwareUsers)
response.write(SofwareUsers(i) & "<br>")
next

Just a side note here, but I often work though one dimensional arrays by working with them as a collection. i.e.

for each item in Softwareusers
response.write(item & "<br>")
next

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top