danielmohr91 Posted December 7, 2009 Share Posted December 7, 2009 (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 December 7, 2009 by danielmohr91 Link to comment Share on other sites More sharing options...
BugFix Posted December 7, 2009 Share Posted December 7, 2009 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 Link to comment Share on other sites More sharing options...
martin Posted December 7, 2009 Share Posted December 7, 2009 .. 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. Link to comment Share on other sites More sharing options...
danielmohr91 Posted December 7, 2009 Author Share Posted December 7, 2009 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now