Jump to content

Easy if and else


Go to solution Solved by argumentum,

Recommended Posts

Posted
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=U:\Code-au3\tempCode\Form1.kxf
$Form1 = GUICreate("Form1", 405, 148)
$Label1 = GUICtrlCreateLabel("Enter a number higher than zero", 10, 10, 200, 17)
$Input1 = GUICtrlCreateInput("0", 10, 40, 50, 21)
$Button1 = GUICtrlCreateButton("Run / Go / action", 70, 40, 200, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            If Number(GUICtrlRead($Input1)) > 0 Then
                MsgBox(0, '', 'class ok, bye', 0, $Form1)
                ExitLoop
            Else
                MsgBox(0, 'ERROR', "Class number must be one number.", 0, $Form1)
            EndIf
    EndSwitch
WEnd

..subscribe, like and comment :D

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • Solution
Posted (edited)
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

ConsoleWrite("+ classNumber() returned: " & classNumber() & " - @error = " & @error & " - @extended = " & @extended & @CRLF)
Func classNumber()
    Local $iReturn, $Form1 = GUICreate("Form1", 405, 148)
    Local $Label1 = GUICtrlCreateLabel("Enter a number higher than zero", 10, 10, 200, 17)
    Local $Input1 = GUICtrlCreateInput("0", 10, 40, 50, 21)
    Local $Button1 = GUICtrlCreateButton("Run / Go / action", 70, 40, 200, 25)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                $iReturn = Number(GUICtrlRead($Input1))
                GUIDelete($Form1)
                Return SetError(1, $iReturn, 0)
            Case $Button1
                $iReturn = Number(GUICtrlRead($Input1))
                If $iReturn > 0 Then
                    MsgBox(0, '', 'class ok, bye', 0, $Form1)
                    GUIDelete($Form1)
                    Return SetError(0, $iReturn, $iReturn)
                Else
                    MsgBox(0, 'ERROR', "Class number must be one number.", 0, $Form1)
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>classNumber

..this would make more sense because I doubt that this is the application you are after, so, running the function returns the value that you'll use elsewhere to do something with it.

In any case, post if this is all you needed to solve, or if is not what you wanted.

Edited by argumentum
better

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted
16 minutes ago, Kralamour said:

why i need to click 10 time for valid

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

ConsoleWrite("+ classNumber() returned: " & classNumber() & " - @error = " & @error & " - @extended = " & @extended & @CRLF)
Func classNumber()
    Local $iReturn, $Form1 = GUICreate("Form1", 405, 148)
    Local $Label1 = GUICtrlCreateLabel("Enter a number higher than zero", 10, 10, 200, 17)
    Local $Input1 = GUICtrlCreateInput("0", 10, 40, 50, 21)
    Local $Button1 = GUICtrlCreateButton("Run / Go / action", 70, 40, 200, 25, $BS_ICON)
    GUICtrlSetImage(-1, "shell32.dll", 22)
    GUICtrlSetCursor (-1, 0)

    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                $iReturn = Number(GUICtrlRead($Input1))
                GUIDelete($Form1)
                Return SetError(1, $iReturn, 0)
            Case $Button1
                $iReturn = Number(GUICtrlRead($Input1))
                If $iReturn > 0 Then
                    MsgBox(0, '', 'class ok, bye', 0, $Form1)
                    GUIDelete($Form1)
                    Return SetError(0, $iReturn, $iReturn)
                Else
                    MsgBox(0, 'ERROR', "Class number must be one number.", 0, $Form1)
                EndIf
        EndSwitch
    WEnd
EndFunc   ;==>classNumber

GUICtrlCreatePic() will act in press down, GUICtrlCreateButton() will act on the way up. I rather use a button as it has the expected behavior.
Why you need to click repeatedly to make it work, is outside the code you shared.

Since the question you had was answered and a future "answer seekers" may find the answer to their question on this thread, is advised to open another thread with running code ( not just an unrelated snippet ) so that it can be looked at without confusion for the reader.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

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
  • Recently Browsing   0 members

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