PDA

View Full Version : compare 3 numbers


landon11
03-26-2003, 04:31 PM
Whats the best way to compare 3 numbers to order them from lowest to highest. Say I have:
iNum1 = 3
iNum2 = 1
iNum3 = 2

Spudhead
03-26-2003, 04:44 PM
Got me stumped, this. I'd be interested in seeing solutions. At first glance, I'd say some sort of looping-through-arrays approach; track the highest number so far, add the current number in original array at the end of new array if its higher, keep looping until new array is same length as original one. But then you've got a few problems to get round.* The other way, which I'm even less sure about, is to create a recordset with these values and then just run a query on it with an ORDER BY in it. Innit. :)

*Actually, that wouldn't work at all, would it? Never mind. I'll think of something.... :thumbsup:

Spudhead
03-26-2003, 04:52 PM
Altervatively, search for "Bubble sort":) The script here looks as though it can be tailored to meet your needs...

http://javascript.internet.com/calculators/bubble-sort.html

landon11
03-26-2003, 04:59 PM
Thank you, that is sort of how I am doing it but I was hoping there might be a simpler method.

raf
03-26-2003, 06:01 PM
If your using Jscript as a scriptinglanguage, use sort mehod



more info from helpfile:
--------------------------------------------------------------------------
sort Method Language Reference
Version 2


See Also Applies To

Description
Returns an Array objec with the elements sorted.

Syntax
arrayobj.sort(sortfunction)
The sortfunction argument is the name of the function used to determine the order of the elements. If omitted, the elements are sorted in ascending, ASCII character order.

Remarks
The sort method sorts the Array object in place; no new Array object is created during execution.
If you supply a function in the sortfunction argument, it must return one of the following values:

A negative value if the first argument passed is less than the second argument.
Zero if the two arguments are equivalent.
A positive value if the first argument is greater than the second argument.
The following example illustrates the use of the sort method:

landon11
03-26-2003, 06:27 PM
Now thats what I was looking for, is there anything similar in vbscript?

raf
03-27-2003, 07:37 AM
This should be exactlu what you're looking after (as if i know...):D

http://search.botbot.com/bot/m/d.html$Asp%20Array%20Sort?045611003

edit:
the url cam out wrong, but (it's magic), returned a whole bunch of useful links.

This was the page i wanted to link to
http://www.4guysfromrolla.com/webtech/012799-3.shtml