# Order from least to greatest

## Recommended Posts

Im making a script that will find everything I need to help me get through my math home work... and I need to find how to order 9 numbers from least to greatest (to find the median), would I be able to do it with strings? if so how?

EDIT: ALSO, how would I be able to find the number with greatest value (MODE), do I have to use ALL those IF...Then commands?

```#include <GuiConstants.au3>

GuiCreate("Math Helper", 351, 163,-1, -1 , BitOR(\$WS_OVERLAPPEDWINDOW, \$WS_CLIPSIBLINGS))

\$Input_1 = GuiCtrlCreateInput("", 10, 10, 30, 20)
\$Input_2 = GuiCtrlCreateInput("", 40, 10, 30, 20)
\$Input_3 = GuiCtrlCreateInput("", 70, 10, 30, 20)
\$Input_4 = GuiCtrlCreateInput("", 100, 10, 30, 20)
\$Input_5 = GuiCtrlCreateInput("", 130, 10, 30, 20)
\$Input_6 = GuiCtrlCreateInput("", 160, 10, 30, 20)
\$Input_7 = GuiCtrlCreateInput("", 190, 10, 30, 20)
\$Input_8 = GuiCtrlCreateInput("", 220, 10, 30, 20)
\$Input_9 = GuiCtrlCreateInput("", 250, 10, 30, 20)
\$Button_10 = GuiCtrlCreateButton("ENTER", 280, 10, 60, 20)
\$Label_11 = GuiCtrlCreateLabel("Mean:", 10, 40, 40, 20)
\$Input_12 = GuiCtrlCreateInput("", 70, 40, 90, 20,\$ES_READONLY)
\$Label_13 = GuiCtrlCreateLabel("Median:", 10, 70, 40, 20,\$ES_READONLY)
\$Input_14 = GuiCtrlCreateInput("", 70, 70, 90, 20,\$ES_READONLY)
\$Input_15 = GuiCtrlCreateInput("", 70, 100, 90, 20,\$ES_READONLY)
\$Label_16 = GuiCtrlCreateLabel("Mode", 10, 100, 50, 20)
\$Label_17 = GuiCtrlCreateLabel("Scale", 190, 40, 40, 20)
\$Label_18 = GuiCtrlCreateLabel("Interval", 190, 70, 40, 20)
\$Label_19 = GuiCtrlCreateLabel("Range", 190, 100, 40, 20)
\$Input_20 = GuiCtrlCreateInput("", 250, 40, 90, 20,\$ES_READONLY)
\$Input_21 = GuiCtrlCreateInput("", 250, 70, 90, 20,\$ES_READONLY)
\$Input_22 = GuiCtrlCreateInput("", 250, 100, 90, 20,\$ES_READONLY)
\$Input_23 = GuiCtrlCreateInput("ORDER", 10, 130, 330, 20,\$ES_READONLY)
GuiSetState()
While 1
\$msg = GuiGetMsg()
Select
Case \$msg = \$Button_10
\$MEAN=\$1 + \$2 + \$3 + \$4 + \$5 + \$6 + \$7 + \$8 + \$9
\$MEAN=\$MEAN / 9
\$MEAN=Round(\$MEAN,2)
GUICtrlSetData(\$Input_12,\$MEAN)
;?????????
Case \$msg = \$GUI_EVENT_CLOSE
ExitLoop
Case Else
;;;
EndSelect
WEnd
Exit```
Edited by P a R a D o X

If I hadn't said thank you yet, and you deserve it, than thank you...

##### Share on other sites

Research this in the help file.

```#include <Array.au3>
_ArraySort ( ByRef \$a_Array, [\$i_Descending[, \$i_Base=0[, \$i_Ubound=0[, \$i_Dim=1[, \$i_SortIndex=0]]]]] )```

Agreement is not necessary - thinking for one's self is!

##### Share on other sites

I think it would be the best to use arrays for that job

##### Share on other sites

theres one problem though, it only sorts my numbers by the first number, like:

82342

9347

183

23

453

78832

63

592

399999

it would come out:

9347

82342

78832

63

592

453

399999

23

183

And im using this:

_ArraySort( \$avArray,1)

how do I fix this?

If I hadn't said thank you yet, and you deserve it, than thank you...

##### Share on other sites

and if you do \$avArray[0] = Number(GUICtrlRead(\$Input_X)) how does it sort? If you're still having issues, I wrote something to do this before for Valuater, I'll have to find it.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

could just pad with zeros using stringformat and then convert back to numbers using number function which should strip the zeros back off

Don't argue with an idiot; people watching may not be able to tell the difference.

##### Share on other sites

theres one problem though, it only sorts my numbers by the first number, like:

82342

9347

183

23

453

78832

63

592

399999

it would come out:

9347

82342

78832

63

592

453

399999

23

183

And im using this:

_ArraySort( \$avArray,1)

how do I fix this?

I remembered what i did on the old listview sort routine to handle numbers

on your read convert it to a number, the read returns a string, the sort should work as wanted then

i.e.

[autoit]

_ArraySort( \$avArray,1)

Don't argue with an idiot; people watching may not be able to tell the difference.

##### Share on other sites

I remembered what i did on the old listview sort routine to handle numbers

on your read convert it to a number, the read returns a string, the sort should work as wanted then

i.e.

[autoit]

_ArraySort( \$avArray,1)

hmmm

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

##### Share on other sites

Kwah, thanks guys... and wheres that link supposed to go?? it just takes me back here....wait is it supposed to do that?...i am really dull now... well i think i am.. but then... ok what ever nvm, thanks again

If I hadn't said thank you yet, and you deserve it, than thank you...

##### Share on other sites

Kwah, thanks guys... and wheres that link supposed to go?? it just takes me back here....wait is it supposed to do that?...i am really dull now... well i think i am.. but then... ok what ever nvm, thanks again

He was just messing with me....

Don't argue with an idiot; people watching may not be able to tell the difference.

## Create an account

Register a new account

×

• Wiki

• Back

• Git