gfunk999 Posted September 13, 2007 Share Posted September 13, 2007 Please help, I'm trying to figure a way to allow only numbers in my input box, but I'm failing. Could someone give me a hint. I tried inserting this piece of code, but it's not working. Perhaps i'm inserting wrong, or it's just flat out wrong. If Number($Input_2) > 0 Then Select Case $msg = $Button_3 exitloop EndSelect Else $err = MsgBox(5, "Error", "A number is required") If $err = 2 Then Exit EndIf EndIf #include <GuiConstants.au3> GuiCreate("MyGUI", 142, 53,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Input_2 = GuiCtrlCreateInput("Number Only", 10, 10, 120, 30) $Button_3 = GuiCtrlCreateButton("OK", 110, 120, 50, 21) GuiSetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $Button_3 exitloop EndSelect Wend if $msg = -3 Then Exit EndIf MsgBox (4096, "Test", GUICtrlRead($Input_2)) Link to comment Share on other sites More sharing options...
BigDod Posted September 13, 2007 Share Posted September 13, 2007 #include <GUIConstants.au3> GuiCreate("MyGUI", 170, 200,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Input_2 = GuiCtrlCreateInput("", 10, 10, 120, 30,$ES_NUMBER) $Button_3 = GuiCtrlCreateButton("OK", 110, 120, 50, 21) GuiSetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $Button_3 exitloop EndSelect Wend if $msg = -3 Then Exit EndIf MsgBox (4096, "Test", GUICtrlRead($Input_2)) Time you enjoyed wasting is not wasted time ......T.S. Elliot Suspense is worse than disappointment................Robert Burns God help the man who won't help himself, because no-one else will...........My Grandmother Link to comment Share on other sites More sharing options...
gfunk999 Posted September 13, 2007 Author Share Posted September 13, 2007 Thanks for the quick reply BigDod! I could not find this style in the help section. For furture reference is there a master list? #include <GUIConstants.au3> GuiCreate("MyGUI", 170, 200,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Input_2 = GuiCtrlCreateInput("", 10, 10, 120, 30,$ES_NUMBER) $Button_3 = GuiCtrlCreateButton("OK", 110, 120, 50, 21) GuiSetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $Button_3 exitloop EndSelect Wend if $msg = -3 Then Exit EndIf MsgBox (4096, "Test", GUICtrlRead($Input_2)) Link to comment Share on other sites More sharing options...
gfunk999 Posted September 13, 2007 Author Share Posted September 13, 2007 Never mind I found it. Thanks again!Thanks for the quick reply BigDod! I could not find this style in the help section. For furture reference is there a master list? Link to comment Share on other sites More sharing options...
gfunk999 Posted September 15, 2007 Author Share Posted September 15, 2007 (edited) Another question if you guys don't mind... My code now accepts only numbers, and I set a max limit of 6 characters; which is what I want. However, I would also like to set a minimum of 4 characters that can be entered. I.E. So if I enter 3 characters the program should not proceed. Do I need another while loop? to include this code: $msg1 = 1 While $msg1 = 1 GUICtrlRead ($input_2) If < 999 Then $min = MsgBox(5, "Error", "Enter more than 3 digits") If $min = 2 Then Exit EndIf Else $msg1 = 0 EndIf WEnd #include <GUIConstants.au3> GuiCreate("MyGUI", 170, 200,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Input_2 = GuiCtrlCreateInput("", 10, 10, 120, 30,$ES_NUMBER) $Button_3 = GuiCtrlCreateButton("OK", 110, 120, 50, 21) GUICtrlSetLimit (3, 6) GuiSetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $Button_3 exitloop EndSelect Wend if $msg = -3 Then Exit EndIf MsgBox (4096, "Test", GUICtrlRead($Input_2)) Edited September 15, 2007 by gfunk999 Link to comment Share on other sites More sharing options...
Generator Posted September 15, 2007 Share Posted September 15, 2007 You can use this If StringLen(GUICtrlRead($Input_2)) < 4 Then ToolTip("Please enter more than 4 digits") Return Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted September 15, 2007 Moderators Share Posted September 15, 2007 You can use this If StringLen(GUICtrlRead($Input_2)) < 4 Then ToolTip("Please enter more than 4 digits") ReturnGUICtrlSetLimit($Input_2, 6, 4)? Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
martin Posted September 15, 2007 Share Posted September 15, 2007 (edited) Another question if you guys don't mind... My code now accepts only numbers, and I set a max limit of 6 characters; which is what I want. However, I would also like to set a minimum of 4 characters that can be entered. I.E. So if I enter 3 characters the program should not proceed. Do I need another while loop? to include this code: $msg1 = 1 While $msg1 = 1 GUICtrlRead ($input_2) If < 999 Then $min = MsgBox(5, "Error", "Enter more than 3 digits") If $min = 2 Then Exit EndIf Else $msg1 = 0 EndIf WEnd #include <GUIConstants.au3> GuiCreate("MyGUI", 170, 200,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Input_2 = GuiCtrlCreateInput("", 10, 10, 120, 30,$ES_NUMBER) $Button_3 = GuiCtrlCreateButton("OK", 110, 120, 50, 21) GUICtrlSetLimit (3, 6) GuiSetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $Button_3 exitloop EndSelect Wend if $msg = -3 Then Exit EndIf MsgBox (4096, "Test", GUICtrlRead($Input_2)) You could do this #include <GUIConstants.au3> GuiCreate("MyGUI", 170, 200,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Input_2 = GuiCtrlCreateInput("", 10, 10, 120, 30,$ES_NUMBER) GUICtrlSetLimit (-1,6);<----------if this is after the input2 creation line it will work even if other components are created before input2 $Button_3 = GuiCtrlCreateButton("OK", 110, 120, 50, 21) ;GUICtrlSetLimit (3, 6)<---------------ID of 3 cannot be guaranteed for Input2 GuiSetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $Button_3 If StringLen($Button_3) > 2 Then exitloop EndSelect Wend if $msg = -3 Then Exit EndIf MsgBox (4096, "Test", GUICtrlRead($Input_2)) NB your SetLimit(3,6) is not a good idea. It might work since your edit was the second thing created, but if in the future it could fall over if you add any components before it. Best to do it the way I did in my change to your code. Edited September 15, 2007 by martin 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...
Generator Posted September 15, 2007 Share Posted September 15, 2007 GUICtrlSetLimit($Input_2, 6, 4)?Well i tried that and you still can enter as many chars as you want as long as it's below 6, the minimum didn't really work. Link to comment Share on other sites More sharing options...
martin Posted September 15, 2007 Share Posted September 15, 2007 Well i tried that and you still can enter as many chars as you want as long as it's below 6, the minimum didn't really work.NO, you can't have a minimum setting for the number of characters in an edit, how would you enter the first character? 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...
Moderators SmOke_N Posted September 15, 2007 Moderators Share Posted September 15, 2007 NO, you can't have a minimum setting for the number of characters in an edit, how would you enter the first character?Ha! That's what I get for never using a function (and not RTFM!!) Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
gfunk999 Posted September 15, 2007 Author Share Posted September 15, 2007 (edited) Thanks guys, i combined both Generator's and martin's suggestions. It works great! Thanks again!!! #include <GUIConstants.au3> GuiCreate("MyGUI", 170, 200,-1, -1 , BitOR($WS_OVERLAPPEDWINDOW, $WS_CLIPSIBLINGS)) $Input_2 = GuiCtrlCreateInput("", 10, 10, 120, 30,$ES_NUMBER) GUICtrlSetLimit (-1,6);<----------if this is after the input2 creation line it will work even if other components are created before input2 $Button_3 = GuiCtrlCreateButton("OK", 110, 120, 50, 21) ;GUICtrlSetLimit (3, 6)<---------------ID of 3 cannot be guaranteed for Input2 GuiSetState() $msg = 0 While $msg <> $GUI_EVENT_CLOSE $msg = GUIGetMsg() Select Case $msg = $Button_3 If StringLen(GUICtrlRead($Input_2)) > 4 Then exitloop ToolTip("Please enter more than 4 digits") EndSelect Wend if $msg = -3 Then Exit EndIf MsgBox (4096, "Test", GUICtrlRead($Input_2)) Edited September 15, 2007 by gfunk999 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