Jump to content
Sign in to follow this  
Vindicator

Order from least to greatest

Recommended Posts

Vindicator

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
$1=GUICtrlRead($Input_1)
$2=GUICtrlRead($Input_2)
$3=GUICtrlRead($Input_3)
$4=GUICtrlRead($Input_4)
$5=GUICtrlRead($Input_5)
$6=GUICtrlRead($Input_6)
$7=GUICtrlRead($Input_7)
$8=GUICtrlRead($Input_8)
$9=GUICtrlRead($Input_9)
    $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 this post


Link to post
Share on other sites
Fossil Rock

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!

My-Colors.jpg

cuniform2.gif

Share this post


Link to post
Share on other sites
Schatten

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

Share this post


Link to post
Share on other sites
Vindicator

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:

$avArray[0]=GUICtrlRead($Input_1)

$avArray[1]=GUICtrlRead($Input_2)

$avArray[2]=GUICtrlRead($Input_3)

$avArray[3]=GUICtrlRead($Input_4)

$avArray[4]=GUICtrlRead($Input_5)

$avArray[5]=GUICtrlRead($Input_6)

$avArray[6]=GUICtrlRead($Input_7)

$avArray[7]=GUICtrlRead($Input_8)

$avArray[8]=GUICtrlRead($Input_9)

_ArraySort( $avArray,1)

how do I fix this?


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

Share this post


Link to post
Share on other sites
SmOke_N

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 this post


Link to post
Share on other sites
GaryFrost

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


SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Share this post


Link to post
Share on other sites
GaryFrost

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:

$avArray[0]=GUICtrlRead($Input_1)

$avArray[1]=GUICtrlRead($Input_2)

$avArray[2]=GUICtrlRead($Input_3)

$avArray[3]=GUICtrlRead($Input_4)

$avArray[4]=GUICtrlRead($Input_5)

$avArray[5]=GUICtrlRead($Input_6)

$avArray[6]=GUICtrlRead($Input_7)

$avArray[7]=GUICtrlRead($Input_8)

$avArray[8]=GUICtrlRead($Input_9)

_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]

$avArray[0]=Number(GUICtrlRead($Input_1))

$avArray[1]=Number(GUICtrlRead($Input_2))

$avArray[2]=Number(GUICtrlRead($Input_3))

$avArray[3]=Number(GUICtrlRead($Input_4))

$avArray[4]=Number(GUICtrlRead($Input_5))

$avArray[5]=Number(GUICtrlRead($Input_6))

$avArray[6]=Number(GUICtrlRead($Input_7))

$avArray[7]=Number(GUICtrlRead($Input_8))

$avArray[8]=Number(GUICtrlRead($Input_9))

_ArraySort( $avArray,1)


SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Share this post


Link to post
Share on other sites
SmOke_N

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]

$avArray[0]=Number(GUICtrlRead($Input_1))

$avArray[1]=Number(GUICtrlRead($Input_2))

$avArray[2]=Number(GUICtrlRead($Input_3))

$avArray[3]=Number(GUICtrlRead($Input_4))

$avArray[4]=Number(GUICtrlRead($Input_5))

$avArray[5]=Number(GUICtrlRead($Input_6))

$avArray[6]=Number(GUICtrlRead($Input_7))

$avArray[7]=Number(GUICtrlRead($Input_8))

$avArray[8]=Number(GUICtrlRead($Input_9))

_ArraySort( $avArray,1)

hmmm

http://www.autoitscript.com/forum/index.ph...st&p=263043

:whistle:


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 this post


Link to post
Share on other sites
Vindicator

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 this post


Link to post
Share on other sites
GaryFrost

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.... :whistle:


SciTE for AutoItDirections for Submitting Standard UDFs

 

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

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.