Sign in to follow this  
Followers 0
danielmohr91

Limit GUI input?

4 posts in this topic

#1 ·  Posted (edited)

I'm working on my first GUI. I need to to set a min and max number that can be entered in the input field. It's just the standard GUICtrlCreateInput with up and down arrows for changing the number. Right now I've got a func that checks it before the code executes, but it's buggy, and I'd like to just block the input in the first place. Is this possible? I was looking at GUICtrlSetLimit but this only limits character length. Thoughts?

Func _check_x_and_y()
    If $x > 22 Then $x = 22
    If $y > 22 Then $y = 22
    If $x < 1 Then $x = 1
    If $y < 0 Then $y = 1
EndFunc   ;==>_check_x_and_y

Or a bit more clumsy...

Func _check_x_and_y()
    If $x > 22 Or $y > 22 Then
        If $x > $y Then
            $ans = $x
        Else
            $ans = $y
        EndIf
        MsgBox(64, "Really?", "Your number was " & $ans & ". Try a number between 1 and 22...")
    EndIf
    If $x < 1 Or $y < 1 Then
        If $x < $y Then
            $ans = $x
        Else
            $ans = $y
        EndIf
        MsgBox(64, "Really?", "I hardly think your number can be " & $ans & ". Try a positive number between 1 and 22...")
    EndIf
    $invalid_num = True
EndFunc   ;==>_check_x_and_y
Edited by danielmohr91

Share this post


Link to post
Share on other sites



By using normal input you got an event by hit ENTER.

Global $minVal = 20, $maxVal = 40

$gui = GUICreate('hit ENTER after input - check starts')
$input = GUICtrlCreateInput('', 10, 10, 100, 20)
GUISetState()


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            Exit
        Case $input
            $read = GUICtrlRead($input)
            If $read < $minVal Or $read > $maxVal Then
                GUICtrlSetData($input, '')
                WinSetTitle($gui, '', 'ERROR - value out of range')
            Else
                WinSetTitle($gui, '', 'OK - value inside range')
            EndIf
    EndSwitch
WEnd

But by using UpDown it doesn't work - the event occurs every time you hit an up/down button. So you need an own button for start check, than it works too.


Best Regards BugFix  

Share this post


Link to post
Share on other sites

.. I was looking at GUICtrlSetLimit but this only limits character length. Thoughts?

It does look like that from the help but also look at GuiCtrlCreateUpDown and you will see that GuiCtrlSetLimit can be used for the MIn and Max values of an UpDown control


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

By using normal input you got an event by hit ENTER.

Global $minVal = 20, $maxVal = 40

$gui = GUICreate('hit ENTER after input - check starts')
$input = GUICtrlCreateInput('', 10, 10, 100, 20)
GUISetState()


While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            Exit
        Case $input
            $read = GUICtrlRead($input)
            If $read < $minVal Or $read > $maxVal Then
                GUICtrlSetData($input, '')
                WinSetTitle($gui, '', 'ERROR - value out of range')
            Else
                WinSetTitle($gui, '', 'OK - value inside range')
            EndIf
    EndSwitch
WEnd

But by using UpDown it doesn't work - the event occurs every time you hit an up/down button. So you need an own button for start check, than it works too.

Thank you so much for writing that code for me! I used your idea and between that, and being able to use GUICtrlSetLimit for the up/down control, it works brilliantly. I adapted your code into a function that also runs at the end of the While loop checking for new changes from the GUI. Thank you, both of you!

It does look like that from the help but also look at GuiCtrlCreateUpDown and you will see that GuiCtrlSetLimit can be used for the MIn and Max values of an UpDown control

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