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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting an Array (low to high) 1

Status
Not open for further replies.

lazytrucker

Programmer
Aug 4, 2004
39
GB
In order to sort an array I have been using this script (below) however the array data is pulled from an external source and the data often has the same value:
eg. MyArray(25,25,25,5,8,2,40,40) when this is the case the array falls down is there any way I can edit my code below to support numbers that are the same.

<%
MyArray=Array(25,14,20,45,25,4,1,31,22,7)
max=ubound(MyArray)

For i=0 to max
For j=i+1 to max
if MyArray(i)>MyArray(j) then
TemporalVariable=MyArray(i)
MyArray(i)=MyArray(j)
MyArray(j)=TemporalVariable
end if
next
next

Response.write ("The sorted values are those ones: <BR>")

For i=0 to max
Response.write (MyArray(i) & "<BR>")
next
%>

Any Suggestions appreciated,

Cheers LazyTrucker.
 
Yoru script worked without any problems for me, tesign on the numbers (25,25,25,5,8,2,40,40) i got the result

2
5
8
25
25
25
40
40

what were you expecting?
 
Right enough it does work with these values in my test environment however the values for the array are in £'s and are taken from an xml file, the values are as follows:

375.20
375.20
537.30
537.30
45.00
45.00
45.00
45.00

When hard coded in the result is:

45
45
45
45
375.2
375.2
537.3
537.3

But when taken from the xml the result is:

375.20
375.20
45.00
45.00
45.00
45.00
537.30
537.30

Any Ideas??
 
It looks like the numbers are being put in the array as text when coming from your XML file, maybe you could convert them to a single (csng())
 
Thanks for the tip I figured it was reading the nums as strings but didnt know how to change them CSng does the trick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top