Sign in to follow this  
Followers 0
Clemens

Wrong Bigger/Smaller Interpretation

5 posts in this topic

I'm really irritated! It's just a simple program whith such a simple algorithm... although with wrong results...

but have a own look:

GLOBAL $num1
GLOBAL $num2

$GUI = GUICreate("Bigger Or Smaller", 220, 110)

GUICtrlCreateLabel("I'll tell you the relation between the numbers", 10, 10)
GUICtrlCreateLabel("  But if you use (for example) 2 and 10", 10, 25)
GUICtrlCreateLabel("  I'll tell you a wrong result!", 10, 40)

$GUIZahl_Start = GUICtrlCreateInput("0", 10, 70, 35, -1, 0x2000)
GUICtrlCreateUpdown(-1)
$GUIZahl_Ende = GUICtrlCreateInput("0", 50, 70, 35, -1, 0x2000)
GUICtrlCreateUpdown(-1)
$GUIKnopf_Start = GUICtrlCreateButton(" Find out ! ", 100, 70)

GUISetState(@SW_SHOW)

LOCAL $GUI_Result
WHILE 1
    $GUI_Result = GUIGetMsg(0)
    IF $GUI_Result = $GUI_EVENT_CLOSE THEN EXIT; "x" or ESC = close program

    IF $GUI_Result = $GUIKnopf_Start THEN
        $num1 = GUICtrlRead($GUIZahl_Start)
        $num2 = GUICtrlRead($GUIZahl_Ende)
        IF $num1 > $num2 THEN      ; BUG!!
            MsgBox(0 + 48, "Interpret", "I say that " & $num1 & " is bigger (>) than " & $num2)
        ELSE
            IF $num1 = $num2 THEN
                MsgBox(0 + 48, "Interpret", "I say that " & $num1 & " is equal (=) " & $num2)
            ELSE
                MsgBox(0 + 48, "Interpret", "I say that " & $num1 & " is smaller (<) than " & $num2)            
            ENDIF
        ENDIF
    ENDIF
WEND

Do you get wrong results, as well?

I'm using AutoIt 3.3.0.0!

Greetings,

Clemens

Share this post


Link to post
Share on other sites



Just some logic errors.

#include <GUIConstants.au3>

Global $num1
Global $num2

$GUI = GUICreate("Bigger Or Smaller", 220, 110)

GUICtrlCreateLabel("I'll tell you the relation between the numbers", 10, 10)
GUICtrlCreateLabel("  But if you use (for example) 2 and 10", 10, 25)
GUICtrlCreateLabel("  I'll tell you a wrong result!", 10, 40)

$GUIZahl_Start = GUICtrlCreateInput("0", 10, 70, 35, -1, 0x2000)
GUICtrlCreateUpdown(-1)
$GUIZahl_Ende = GUICtrlCreateInput("0", 50, 70, 35, -1, 0x2000)
GUICtrlCreateUpdown(-1)
$GUIKnopf_Start = GUICtrlCreateButton(" Find out ! ", 100, 70)

GUISetState(@SW_SHOW)

Local $GUI_Result
While 1
    $GUI_Result = GUIGetMsg(0)
    If $GUI_Result = $GUI_EVENT_CLOSE Then Exit; "x" or ESC = close program

    If $GUI_Result = $GUIKnopf_Start Then
        $num1 = GUICtrlRead($GUIZahl_Start)
        $num2 = GUICtrlRead($GUIZahl_Ende)
        If $num1 = $num2 Then
            MsgBox(0 + 48, "Interpret", "I say that " & $num1 & " is equal (=) " & $num2)
        ElseIf $num1 > $num2 Then
            MsgBox(0 + 48, "Interpret", "I say that " & $num1 & " is bigger (>) than " & $num2)
        ElseIf $num1 < $num2 Then
            MsgBox(0 + 48, "Interpret", "I say that " & $num1 & " is smaller (<) than " & $num2)
        EndIf
    EndIf
WEnd

Share this post


Link to post
Share on other sites

It's comparing them as strings, I'll bet. Try using Number() when pulling the data from the controls.

Share this post


Link to post
Share on other sites

@JamesBrooks: Your code may be more elegant, but the logic is the same ;)

@SkinnyWhiteGuy: This was it! ... what else should it had be :D

Thanks :D

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  
Followers 0