KenNichols Posted June 9, 2009 Share Posted June 9, 2009 If I use the following code it will create an input that will allow only "numbers". Is it possible to create my own style that would allow numbers & ".-"? I will be using it for Currency - example(3.50,-100.00) ----------------------------------------------------------------------------------------------------------------- #include <EditConstants.au3> #include <GUIConstants.au3> $Frm = GUICreate("Test Form",200,100,500,500) $Input = GUICtrlCreateInput("123",10,10,70,18,$ES_NUMBER) GUISetState() While 1 $nMsg = GUIGetMsg(1) Select Case $nMsg[0] = $GUI_EVENT_CLOSE If $nMsg[1] = $Frm Then Exit EndIf EndSelect Sleep(50) WEnd [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner! Link to comment Share on other sites More sharing options...
DarkSprout Posted June 9, 2009 Share Posted June 9, 2009 (edited) If I use the following code it will create an input that will allow only "numbers". Is it possible to create my own style that would allow numbers & ".-"? I will be using it for Currency - example(3.50,-100.00) ----------------------------------------------------------------------------------------------------------------- #include <EditConstants.au3> #include <GUIConstants.au3> $Frm = GUICreate("Test Form",200,100,500,500) $Input = GUICtrlCreateInput("123",10,10,70,18,$ES_NUMBER) GUISetState() While 1 $nMsg = GUIGetMsg(1) Select Case $nMsg[0] = $GUI_EVENT_CLOSE If $nMsg[1] = $Frm Then Exit EndIf EndSelect Sleep(50) WEnd just test to see if the input is a number... Cold Coded: Case $Input If IsNumber(GUICtrlRead($Input)) = False Then MsgBox(.... Error GUICtrlRead($Input) = 0 EndIf Edited June 9, 2009 by DarkSprout =|)arkSprout=VBA | VBScript | C# Programmer [font="Verdana"]"Give a person a fish and you feed them for a day; teach a person to use the Internet and they won't bother you for weeks."[/font] Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 9, 2009 Moderators Share Posted June 9, 2009 KenNichols, Have a look at this post - a "A-Bunch-of-Us-Guys-as-a-Team" came up with it a while ago. ;-) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
KenNichols Posted June 9, 2009 Author Share Posted June 9, 2009 KenNichols, Have a look at this post - a "A-Bunch-of-Us-Guys-as-a-Team" came up with it a while ago. ;-) M23 Thanks, I think I can make this work! ; Restricted keys in an input '[\\/ ?"<>\|,!@#$%^&*()~`=+"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]' ; Author A-Bunch-of-Us-Guys-as-a-Team ...lol GUICreate("Input Filter", 300, 30, -1, -1) Global $inTest = GUICtrlCreateInput("", 5, 5, 290) GUIRegisterMsg(0x0111, "_WM_COMMAND") GUISetState(@SW_SHOW) While GUIGetMsg() <> -3 WEnd GUIRegisterMsg(0x0111, "") Func _WM_COMMAND($hWnd, $iMsg) GUICtrlSetData($inTest, StringRegExpReplace(GUICtrlRead($inTest), '[\\/ ?"<>\|,!@#$%^&*()~`=+"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ]', "")) EndFunc ;==>_WM_COMMAND [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 9, 2009 Moderators Share Posted June 9, 2009 (edited) KenNichols,You might find it a bit easier to use this code:GUICtrlSetData($inTest, StringRegExpReplace(GUICtrlRead($inTest), '[^0-9.-]', ""))The caret inverts the selection - i.e. permits rather than excludes.If you wait for a RegExp guru, they will probably be able to limit the minus sign to the first character and permit only one decimal point, but I am afraid that is beyond me (but not others - see below!)M23P.S. It is much easier for other forum users if you use Code tags. Put [code ] before and [/code ] after your posted code (but omit the trailing space - it is only there so the tags display here). >>>>>>>>>>>>>>>>>> Edit:A bit more searching and I found some other code (credit to rover and MrCreatoR here) which let me develop this code to go in the WM_COMMAND function:Local $Read_Input = GUICtrlRead($inTest) If StringRegExp($Read_Input, '[^\A-{1}][^0-9.]') Then $Read_Input = StringRegExpReplace($Read_Input, '[^\d.-]|([{0-9,1}^\A-])[^\d.]', '\1') Local $Point = StringInStr($Read_Input, ".", 0, 2) If $Point > 0 Then $Read_Input = StringLeft($Read_Input, $Point - 1) GUICtrlSetData($inTest, $Read_Input)This should now limit the input to a leading minus (if needed) and only 1 decimal point - I hope it does what you want.M23 Edited June 9, 2009 by Melba23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
KenNichols Posted June 9, 2009 Author Share Posted June 9, 2009 KenNichols, You might find it a bit easier to use this code:GUICtrlSetData($inTest, StringRegExpReplace(GUICtrlRead($inTest), '[^0-9.-]', "")) The caret inverts the selection - i.e. permits rather than excludes. If you wait for a RegExp guru, they will probably be able to limit the minus sign to the first character and permit only one decimal point, but I am afraid that is beyond me (but not others - see below!) M23 P.S. It is much easier for other forum users if you use Code tags. Put [code ] before and [/code ] after your posted code (but omit the trailing space - it is only there so the tags display here). >>>>>>>>>>>>>>>>>> Edit: A bit more searching and I found some other code (credit to rover and MrCreatoR here) which let me develop this code to go in the WM_COMMAND function:Local $Read_Input = GUICtrlRead($inTest) If StringRegExp($Read_Input, '[^\A-{1}][^0-9.]') Then $Read_Input = StringRegExpReplace($Read_Input, '[^\d.-]|([{0-9,1}^\A-])[^\d.]', '\1') Local $Point = StringInStr($Read_Input, ".", 0, 2) If $Point > 0 Then $Read_Input = StringLeft($Read_Input, $Point - 1) GUICtrlSetData($inTest, $Read_Input) This should now limit the input to a leading minus (if needed) and only 1 decimal point - I hope it does what you want. M23 That is almost perfect! I found that same post and I was looking at http://www.autoitscript.com/autoit3/pcrepattern.html#SEC9 I am having trouble limiting it to 2 digits after the "." [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 9, 2009 Moderators Share Posted June 9, 2009 KenNichols, Do you want fries with that? :-) Try this:#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <EditConstants.au3> GUICreate("Input Filter", 300, 30, -1, -1) Global $inTest = GUICtrlCreateInput("", 5, 5, 290) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") GUISetState(@SW_SHOW) While GUIGetMsg() <> $GUI_EVENT_CLOSE WEnd GUIRegisterMsg($WM_COMMAND, "") Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $iIDFrom = BitAND($wParam, 0xFFFF);LoWord Local $iCode = BitShift($wParam, 16) ;HiWord If $iIDFrom = $inTest And $iCode = $EN_CHANGE Then $Read_Input = GUICtrlRead($inTest) If StringRegExp($Read_Input, '[^\A-{1}][^0-9.]') Then $Read_Input = StringRegExpReplace($Read_Input, '[^\d.-]|([{0-9,1}^\A-])[^\d.]', '\1') $Point1 = StringInStr($Read_Input, ".", 0) $Point2 = StringInStr($Read_Input, ".", 0, 2) If $Point2 <> 0 Then $Read_Input = StringLeft($Read_Input, $Point2 - 1) If $Point1 <> 0 Then $Read_Input = StringLeft($Read_Input, $Point1 + 2) GUICtrlSetData($inTest, $Read_Input) EndIf EndFunc;==>_WM_COMMAND I have also taken the opportunity to add in a bit more checking within the function so it only activates when the particular input is changed. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
KenNichols Posted June 9, 2009 Author Share Posted June 9, 2009 Thanks I had to change this line. It was allowing me to enter letters if no numbers were added first. If StringRegExp($Read_Input, '[^\d.-]|([{0-9,1}^\A-])[^\d.]') Then $Read_Input = StringRegExpReplace($Read_Input, '[^\d.-]|([{0-9,1}^\A-])[^\d.]', '\1') [topic="21048"]New to AutoIt? Check out AutoIt 1-2-3![/topic] Need to make a GUI? You NEED KODA FormDesigner! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted June 10, 2009 Moderators Share Posted June 10, 2009 KenNichols, Glad we got it working - and I learnt a lot as well. :-) M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area 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