Jump to content

sorting user inputs real time logic issue


Recommended Posts

include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 402, 226, 254, 124)
$Input1 = GUICtrlCreateInput("", 32, 64, 153, 21)
$Input2 = GUICtrlCreateInput("", 32, 112, 153, 21)
$Input3 = GUICtrlCreateInput("", 32, 160, 153, 21)
$Label1 = GUICtrlCreateLabel("Number 1", 32, 48, 50, 17)
$Label2 = GUICtrlCreateLabel("Number 2", 32, 96, 50, 17)
$Label3 = GUICtrlCreateLabel("Number 3", 32, 144, 50, 17)
$Label4 = GUICtrlCreateLabel("Enter 3 numbers and the program will display them in order", 32, 16, 277, 17)
$Edit1 = GUICtrlCreateEdit("", 224, 56, 145, 129)
GUICtrlSetData(-1, "Edit1")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


    Global $High = 0, $Mid = 0, $Low = 0
While 1
    Local $Value1 = GUICtrlRead($Input1)
    Local $Value2 = GUICtrlRead($Input2)
    Local $Value3 = GUICtrlRead($Input3)

    If $Value1 >= $Value2 And $Value1 >= $Value3 Then
        $High = $Value1
        If $Value2 >= $Value3 Then
            $Mid = $Value2
            $Low = $Value3
        Else
            $Mid = $Value3
            $Low = $Value2
        EndIf
    EndIf

    If $Value2 >= $Value1 And $Value2 >= $Value3 Then
        $High = $Value2
        If $Value1 >= $Value3 Then
            $Mid = $Value1
            $Low = $Value3
        Else
            $Mid = $Value3
            $Low = $Value1
        EndIf
    EndIf

    If $Value3 >= $Value1 And $Value3 >= $Value2 Then
        $High = $Value3
        If $Value2 >= $Value1 Then
            $Mid = $Value2
            $Low = $Value1
        Else
            $Mid = $Value1
            $Low = $Value2
        EndIf
    EndIf

    GUICtrlSetData($Edit1,$Low & @CRLF & $Mid & @CRLF & $High)


    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

So my brother and I are having a contest where he gives me a problem in his college textbook for Java and I have to complete a program in autoit while he tries to complete it in java. The above problem:

Write a program that sorts three integers.  The integers are entered from the input dialogs and stored into the variables num1, num2, and num3 respectively.  The program sorts the numbers so that num1 <= num2 <= num3.  Output num1, num2, and num3.

My code works properly but there is a problem. If my numbers have a different number of digits in them ie num1 = 1 and num = 12 then autoit doesnt sort them properly. If the numbers have the same number of digits then the above works. Why is this happening?

*Edit - The program sorts by the first digit of each number

Edited by computergroove

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

all your stuff should be number($valueX) or you are evaluating strings

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...