ViciousXUSMC Posted July 20, 2015 Share Posted July 20, 2015 I have used a UDF before that could restrict the data type for an input, and I found this today by searching:But the solution Melba has in that thread causes my input to refresh over and over so it won't work for this situation, As for that UDF I have no idea where that old UDF is. So figured maybe I should just ask as their may be new UDF or new methods that I am not aware of. Basically I have a GUI that asks for the users Name/ID that submits to a database.In production I am having people put a 4 digit number for their name instead of their real name or computer ID so I want to restrict the input to make input of letters mandatory and give a notification of sorts to the user when they try to type numbers so they know why they cant type numbers and what is required in the field. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 20, 2015 Moderators Share Posted July 20, 2015 ViciousXUSMC,That code makes me blush it is so inelegant - I am sure we can do better for you. But:In production I am having people put a 4 digit number for their name instead of their real name or computer ID so I want to restrict the input to make input of letters mandatory and give a notification of sorts to the user when they try to type numbersmakes no sense to me. You start by speaking of entering a 4-digit number and then say that you want to limit the input to letters only. Just what do you want in this input?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...
ViciousXUSMC Posted July 20, 2015 Author Share Posted July 20, 2015 I am asking for Name or ID in the fields label.So I am expecting their real name John Doe or Computer ID JohnDo both of those I know who the person is entering into the database. But this is Fire Services and they are putting in their 911 ID used for CAD and that is a 4 digit number.I have no way to cross reference that 4 digit number to who the person is, so I think the best approach here (since use training is not an option lol) is to restrict input to letters only and block numeric input. My wording may not have been clear but what I intended to say was that my code being used in production did not get desired results where people put their name or computer id and instead they are entering a 4 digit number. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 20, 2015 Moderators Share Posted July 20, 2015 ViciousXUSMC,Try this and see what you think:expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <EditConstants.au3> $hGUI = GUICreate("Test", 500, 500) $cInput = GUICtrlCreateInput("", 10, 10, 200, 20) GUISetState() GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_COMMAND($hWHnd, $iMsg, $wParam, $lParam) ; If it was an update message from our input If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $cInput Then ; Read content $sContent = GUICtrlRead($cInput) ; check if any non-letters If StringRegExp($sContent, "[^A-Za-z]") Then ; Replace any non-letters $sContent = StringRegExpReplace($sContent, "[^A-Za-z]", "") ; Colour input GUICtrlSetBkColor($cInput, 0xFFCCCC) ; Create tootip $aPos = WinGetPos($hGUI) ToolTip("Letters only", $aPos[0] + 30, $aPos[1] + 50, "Error", $TIP_ERRORICON) ; Register function to clear tooltip and reset backcolour AdlibRegister("_ResetBkColor", 1000) EndIf ; Set the label to the new data GUICtrlSetData($cInput, $sContent) EndIf EndFunc ;==>_WM_COMMAND Func _ResetBkColor() AdlibUnRegister("_ResetBkColor") GUICtrlSetBkColor($cInput, 0xFEFEFE) ToolTip("") EndFuncM23 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...
jguinch Posted July 20, 2015 Share Posted July 20, 2015 (edited) Maybe you can use GUIRegisterMsg to intercept the pressed keys, and then show and error message if needed.One example :expandcollapse popup#include <GUIConstantsEx.au3> #Include <WindowsConstants.au3> #Include <EditConstants.au3> GUICreate("GUI") Global $sErrorText = "This caracter is not supported" Global $sAllowedKeys = "[a-zA-Z]" Global $iErrorDuration = 1000 Global $iError = 0, $hTimer = 0 Global $input = GUICtrlCreateInput("", 10, 10, 200, 20) Global $errorLabel = GUICtrlCreateLabel("", 10, 30, 200, 20) GUICtrlSetColor(-1, 0xff0000) GUIRegisterMsg($WM_COMMAND, "MY_WM_COMMAND") GUISetState() While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop If $iError Then ShowError() WEnd Func ShowError() If $hTimer Then If TimerDiff($hTimer) >= $iErrorDuration Then $hTimer = 0 GUICtrlSetData($errorlabel, "") $iError = 0 endIf Else GUICtrlSetData($errorlabel, $sErrorText) $hTimer = TimerInit() EndIf EndFunc Func MY_WM_COMMAND($hWnd, $iMsg, $wParam, $lParam) Local $nNotifyCode = BitShift($wParam, 16) Local $nID = BitAND($wParam, 0x0000FFFF) Local $sInputContent Switch $nID Case $input Switch $nNotifyCode Case $EN_UPDATE If NOT StringRegExp( GUICtrlRead($input), "^" & $sAllowedKeys & "*$") Then $iError = 1 GUICtrlSetData($input, StringRegExpReplace( GUICtrlRead($input), StringRegExpReplace($sAllowedKeys, "^\[\K", "^"), "") ) EndIf EndSwitch EndSwitch EndFunc Edited July 20, 2015 by jguinch Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted July 20, 2015 Author Share Posted July 20, 2015 Ok about to head out into the field for a bit, I'll try both when I get back and give feedback. Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 20, 2015 Moderators Share Posted July 20, 2015 ViciousXUSMC,I'll try both [...] and give feedbackI can hardly wait.... To save you some time, the 2 scripts are essentially the same - looking for a change in input content and replacing any non-letter characters.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...
ViciousXUSMC Posted July 20, 2015 Author Share Posted July 20, 2015 (edited) Melba - Yours works greatWas missing the constant for $TIP_ERRORCORRECTION for some reason. Helpfile says include AutoITConstants.au3 but that did not fix it either so I just changed that to a "3" to make the example work.I found your example easy to integrate into my script and modify the tooltip for the proper position. jguinch - Got yours working as well "character" typo for the label In both cases I need to figure out how to modify the RegEX to allow spaces since First Last name needs a space between. I am sure that is easy enough for me to figure out with some google.Both great working examples and I appreciate the time and effort on both behalves. Edited July 20, 2015 by ViciousXUSMC Link to comment Share on other sites More sharing options...
jguinch Posted July 20, 2015 Share Posted July 20, 2015 I don't know why, but I did not see Melba's code... (sorry) Spoiler Network configuration UDF, _DirGetSizeByExtension, _UninstallList Firefox ConfigurationArray multi-dimensions, Printer Management UDF Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted July 20, 2015 Author Share Posted July 20, 2015 No reason to be sorry, gives me a different code to see a different approach.I figured out how to add space to the RegEX (just add a space lol)Again thanks to both. Link to comment Share on other sites More sharing options...
kylomas Posted July 20, 2015 Share Posted July 20, 2015 ViciousXUSMC,M23's code with another way to handle the invalids input message...expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <WinAPI.au3> #include <EditConstants.au3> #include <GuiEdit.au3> $hGUI = GUICreate("Test", 500, 500) $cInput = GUICtrlCreateInput("", 10, 10, 200, 20) GUISetState() GUIRegisterMsg($WM_COMMAND, "_WM_COMMAND") While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd Func _WM_COMMAND($hWHnd, $iMsg, $wParam, $lParam) ; If it was an update message from our input If _WinAPI_HiWord($wParam) = $EN_CHANGE And _WinAPI_LoWord($wParam) = $cInput Then ; Read content $sContent = GUICtrlRead($cInput) ; check if any non-letters If StringRegExp($sContent, "[^A-Za-z]") Then ; Replace any non-letters $sContent = StringRegExpReplace($sContent, "[^A-Za-z]", "") ; Colour input GUICtrlSetBkColor($cInput, 0xFFCCCC) ; Create tootip _GUICtrlEdit_ShowBalloonTip($cInput,'Input Error','Valid chars are...',$TTI_ERROR) ; <---- another way to display error message AdlibRegister("_ResetBkColor", 1000) EndIf ; Set the label to the new data GUICtrlSetData($cInput, $sContent) EndIf EndFunc ;==>_WM_COMMAND Func _ResetBkColor() AdlibUnRegister("_ResetBkColor") GUICtrlSetBkColor($cInput, 0xFEFEFE) ToolTip("") EndFunckylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill 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