Arranging 4 variables in increasing value

Guys!

I have 4 variables: pos1, pos2, pos3, pos4

I want to arrange these four values in order of ascending values, and store them in variables number1, number2, number3, number4. It doesn’t matter if I know the values in pos1, pos2, pos3, pos4. I just want the smallest value to be stored in number1, and the largest to be number2.

thanks!

Howdy…

I am not quite getting the meaning of that ‘thanks’… Did you solve the problem or not???

Anyways… You can use an array and its sort() function to get what you want to do… Of course there’s gotta be million ways of doing it… :wink:

pos1 = 5;
pos2 = 3;
pos3 = 7;
pos4 = 1;

tempArray = new Array();

for (i = 1 ; i <= 4 ; i++)
{
	tempArray.push(this["pos" + i]);
	trace("pos" + i + " = " + this["pos" + i]);
}
tempArray.sort();

trace("tempArray = " + tempArray);

for (i = 1 ; i <= 4 ; i++)
{
	this["number" + i] = tempArray.shift();
	trace("number" + i + " = " + this["number" + i]);
}

pos1 = 5
pos2 = 3
pos3 = 7
pos4 = 1
tempArray = 1,3,5,7
number1 = 1
number2 = 3
number3 = 5
number4 = 7

I accidentally pressed enter hence the 2nd post. Thanks CyanBlue =)=)

No problem… :wink: