1. RE: Sorting numbers
- Posted by CK Lester <cklester at yahoo.com> Mar 21, 2001
- 425 views
- Last edited Mar 22, 2001
You will no doubt get many "efficiency experts" posting modified code... Here's my contribution. > Here is the code that I was working on before I got stuck. > > global procedure onClick_sparebutton() > atom AB1, AB2, AB3, AB4, AB5, AB6, AB7, AB8 > atom BC1, BC2, BC3, BC4, BC5, BC6, BC7, BC8 > atom CA1, CA2, CA3, CA4, CA5, CA6, CA7, CA8 -- Instead of using all these variables, -- create a sequence of the values you want... atom NUM_TO_GET NUM_TO_GET = 24 -- in case you want to change later sequence allVars allVars = repeat( {} , NUM_TO_GET ) > atom sumAB, sumBC, sumCA, sumtotal > atom sparenumber > object y > AB1 = getNumber( ab1 ) ..snip... > CA8 = getNumber( ca8 ) for t=1 to NUM_TO_GET do -- this gets all the numbers you want allVars[t] = getNumber( allVars[t] ) -- what's up with this? end for > sumAB = AB1 + AB2 + AB3 + AB4 + AB5 + AB6 + AB7 + AB8 > sumBC = BC1 + BC2 + BC3 + BC4 + BC5 + BC6 + BC7 + BC8 > sumCA = CA1 + CA2 + CA3 + CA4 + CA5 + CA6 + CA7 + CA8 Oops. I just noticed this. You can solve this way: 1. Create three sequences, AB, BC, and CA, or 2. Create one sequence with three elements... allVars = { AB_Sequence , BC_Sequence , CA_Sequence } > sumtotal = sumAB + sumBC + sumCA > > y=sort({AB1,AB2,AB3,AB4,AB5,AB6,AB7,AB8,BC1,BC2,BC3,BC4,BC5,BC6,BC > 7,BC8,CA1,CA2,CA3,CA4,CA5,CA6,CA7,CA8}) sorted_vars = sort( AB_Sequence ) -- etc. > I relize it is very imcomplete, but I just don't understand the sort > function Good luck!