James Posted July 30, 2007 Share Posted July 30, 2007 Hey, I am wandering how I would only let my input allow numbers: 1234567890 and functions: +-*/ only. I tried: Func Acceptions($io_control) $io_read = GuiCtrlRead($io_control) If StringIsAlpha($io_read) Then GuiCtrlSetTip($io_control, "1234567890 and +-*/ only!") EndIf EndFunc I also tried using $ES_Numbers but that wont allow me to us +-*/ Any thoughts? -James Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
ashley Posted July 30, 2007 Share Posted July 30, 2007 urm... try thisHotKeySet("a", "donothing"); and so on... just keep going acroos keyboard with or inbetween HotKeySet("s", "donothing") HotKeySet("d", "donothing")oÝ÷ Ù©Ýjëh×6 Func donothing() endfunc not tested Free icons for your programs Link to comment Share on other sites More sharing options...
bluebearr Posted July 30, 2007 Share Posted July 30, 2007 Here's an idea: $test = "23456-" MsgBox(0, "Test", $test & " returns " & _IsNumAndSymbols($test)) Func _IsNumAndSymbols($strInput) $aInput = StringSplit($strInput, "") For $i = 1 to $aInput[0] If Not StringInStr("1234567890+-*", $aInput[$i]) Then Return False EndIf Next Return True EndFunc BlueBearrOddly enough, this is what I do for fun. Link to comment Share on other sites More sharing options...
ashley Posted July 30, 2007 Share Posted July 30, 2007 urm... try thisHotKeySet("a", "donothing"); and so on... just keep going acroos keyboard with or inbetween HotKeySet("s", "donothing") HotKeySet("d", "donothing")oÝ÷ Ù©Ýjëh×6 Func donothing() endfunc not testedi know its a long way round but thats all i can think of... Free icons for your programs Link to comment Share on other sites More sharing options...
James Posted July 30, 2007 Author Share Posted July 30, 2007 (edited) I will try that now bluebearr. I didn't think of that Whoops. I dont want to be able to enter letters or !"£$%^& into the input. Edited July 30, 2007 by NeoTroniX Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
weaponx Posted July 30, 2007 Share Posted July 30, 2007 ;Test String $STRING = "1234567890+-*/" ;Regex only allow 0-9 +-*/ $RESULT = StringRegExp ( $STRING, "[^0-9\-\+\*\/]") MsgBox(0,"",$RESULT) Link to comment Share on other sites More sharing options...
James Posted July 30, 2007 Author Share Posted July 30, 2007 Thanks for trying but it doesn't work I really should know how to do this. But I don't. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
bluebearr Posted July 30, 2007 Share Posted July 30, 2007 Based on your example in your OP, the following should work: $io_read = GuiCtrlRead($io_control) If Not _IsNumAndSymbols($io_read) Then GuiCtrlSetTip($io_control, "1234567890 and +-*/ only!") Func _IsNumAndSymbols($strInput) $aInput = StringSplit($strInput, "") For $i = 1 to $aInput[0] If Not StringInStr("1234567890+-*", $aInput[$i]) Then Return False EndIf Next Return True EndFuncoÝ÷ ØêÞ½éÚºÚ"µÍÌÍÚ[×ÜXYHÝZPÝXY ÌÍÚ[×ØÛÛÛ BYÝ[ÔYÑ^ ÌÍÚ[×ÜXY ][ÝÖ×NIÌLËIÌLÊÉÌLÊÌLË×I][ÝÊH ÉÝÈ[ÝZPÝÙ] ÌÍÚ[×ØÛÛÛ ][ÝÌLÍ MÎL[ ËJÈÛIÌÌÎÉ][ÝÊ What is failing? Are you getting an error? BlueBearrOddly enough, this is what I do for fun. Link to comment Share on other sites More sharing options...
James Posted July 30, 2007 Author Share Posted July 30, 2007 Nothing happens. I can still type letters in there. Its annoying me as I should know. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
bluebearr Posted July 30, 2007 Share Posted July 30, 2007 Is this kind of what you are trying to do? expandcollapse popup#include <GUIConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Test", 410, 193, 193, 115) $Label1 = GUICtrlCreateLabel("Enter data:", 32, 48, 56, 17) $io_control = GUICtrlCreateInput("", 104, 48, 201, 21) $Button1 = GUICtrlCreateButton("OK", 168, 136, 65, 25, $BS_DEFPUSHBUTTON) $Label2 = GUICtrlCreateLabel("", 104, 88, 235, 41) GUICtrlSetColor ( -1, 0xff0000) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE If _GoodData() Then ExitLoop Case $Button1 If _GoodData() Then ExitLoop EndSwitch WEnd GUIDelete($Form1) MsgBox(0, "End", "End of script") Func _GoodData() $io_read = GuiCtrlRead($io_control) If $io_read = "" Or StringRegExp( $io_read, "[^0-9\-\+\*\/]") <> 0 Then GuiCtrlSetTip($io_control, "1234567890 and +-*/ only!") GUICtrlSetData($Label2, "1234567890 and +-*/ only!") Return False Else GUICtrlSetData($Label2, "") Return True EndIf EndFunc BlueBearrOddly enough, this is what I do for fun. Link to comment Share on other sites More sharing options...
James Posted July 30, 2007 Author Share Posted July 30, 2007 Yes, but I need to block letters from being entered. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
xcal Posted July 30, 2007 Share Posted July 30, 2007 (edited) #include <GUIConstants.au3> GUICreate('') $input = GUICtrlCreateInput('', 10, 10, 100, 20) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch _checkinput() WEnd Func _checkinput() Local $filter = '1234567890/*+-', $str = GUICtrlRead($input), $split If $str <> '' Then $split = StringSplit($str, '') If Not StringInStr($filter, $split[$split[0]]) Then GUICtrlSetData($input, StringTrimRight($str, 1)) EndIf EndFunc Edited July 30, 2007 by xcal How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
ChrisL Posted July 30, 2007 Share Posted July 30, 2007 #include <GUIConstants.au3> GUICreate('') $input = GUICtrlCreateInput('', 10, 10, 100, 20,Bitor($GUI_SS_DEFAULT_INPUT ,$ES_NUMBER)) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd [u]Scripts[/u]Minimize gui to systray _ Fail safe source recoveryMsgbox UDF _ _procwatch() Stop your app from being closedLicensed/Trial software system _ Buffering Hotkeys_SQL.au3 ADODB.Connection _ Search 2d Arrays_SplashTextWithGraphicOn() _ Adjust Screen GammaTransparent Controls _ Eventlogs without the crap_GuiCtrlCreateFlash() _ Simple Interscript communication[u]Websites[/u]Curious Campers VW Hightops Lambert Plant Hire Link to comment Share on other sites More sharing options...
James Posted July 30, 2007 Author Share Posted July 30, 2007 Thanks guys. I should of known what to do. But I just couldn't think. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
xcal Posted July 30, 2007 Share Posted July 30, 2007 #include <GUIConstants.au3> GUICreate('') $input = GUICtrlCreateInput('', 10, 10, 100, 20,Bitor($GUI_SS_DEFAULT_INPUT ,$ES_NUMBER)) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd I also tried using $ES_Numbers but that wont allow me to us +-*/ How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
James Posted July 30, 2007 Author Share Posted July 30, 2007 Yeah, xcal your way worked. I know I added an extra letter then. $ES_NUMBER Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
xcal Posted July 30, 2007 Share Posted July 30, 2007 My way is kind of hackerish, though. I did a little searching on "masked edit controls" and did find some info, but couldn't figure how to translate it in to something Autoit would understand. Maybe someone with some more brains can figure out the proper way. How To Ask Questions The Smart Way Link to comment Share on other sites More sharing options...
James Posted July 30, 2007 Author Share Posted July 30, 2007 It works fine for me, so I will use it :Pq Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ Link to comment Share on other sites More sharing options...
jvanegmond Posted July 30, 2007 Share Posted July 30, 2007 (edited) My way is kind of hackerish, though. I did a little searching on "masked edit controls" and did find some info, but couldn't figure how to translate it in to something Autoit would understand. Maybe someone with some more brains can figure out the proper way.Don't go that way. Your way is perfect, and is commonly used by a lot of programs. Also, I made this a lot faster using a regular expression. #include <GUIConstants.au3> GUICreate('') $input = GUICtrlCreateInput('', 10, 10, 100, 20) GUISetState() While 1 $msg = GUIGetMsg() Switch $msg Case $GUI_EVENT_CLOSE Exit EndSwitch _checkinput() WEnd Func _checkinput() Local $str = GUICtrlRead($input) $strmod = StringRegExpReplace( $str, "[^0-9\-\+\*\/]","") If $str <> $strmod Then GUICtrlSetData($input,$strmod) EndFunc Edited July 30, 2007 by Manadar github.com/jvanegmond Link to comment Share on other sites More sharing options...
James Posted July 30, 2007 Author Share Posted July 30, 2007 Thanks Manadar and xcal You just cut down my script. Blog - Seriously epic web hosting - Twitter - GitHub - Cachet HQ 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