dixonpete Posted October 20, 2011 Posted October 20, 2011 I'm using GUICtrlCreateInput to create an input field that I need to validate after the person has typed something into the field. Is this possible? I don't seem to see any options for that in the Help file.
funkey Posted October 20, 2011 Posted October 20, 2011 Search for RestrictControlRegExp. Programming today is a race between software engineers striving tobuild bigger and better idiot-proof programs, and the Universetrying to produce bigger and better idiots.So far, the Universe is winning.
Moderators Melba23 Posted October 20, 2011 Moderators Posted October 20, 2011 dixonpete, Easy - in some cases you can even validate the input while the user is actually entering the data. What sort of validation are we talking about here? 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
dixonpete Posted October 20, 2011 Author Posted October 20, 2011 I'm looking to check the results after leaving the field and immediately put up a MsgBox asking for a decision to be made. I.e., a database with that name already exists, do you want to overwrite it or merge into it. Didn't have much luck finding 'RestrictControlRegExp' in the Help. dixonpete, Easy - in some cases you can even validate the input while the user is actually entering the data. What sort of validation are we talking about here? M23
Moderators Melba23 Posted October 20, 2011 Moderators Posted October 20, 2011 dixonpete,That is trivial: #include <GUIConstantsEx.au3> $sExt = ".fil" ; We will force the new name to have this extension reqgardless of what the user adds or omits $hGUI = GUICreate("Enter a name for the database", 320,120) $hName = GUICtrlCreateInput ( "", 10, 20, 300, 20) $hButton = GUICtrlCreateButton ("Ok", 40, 95, 60, 20) GuiSetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hButton $sNew_Name = GUICtrlRead($hName) ; Force the correct extension If Not StringRegExp($sNew_Name, ".*\" & $sExt) Then $sNew_Name = StringRegExpReplace($sNew_Name, "^.*\\|\..*$", "") & $sExt EndIf ; Display it to show it works ConsoleWrite($sNew_Name & @CRLF) ; See if the file exists If FileExists($sNew_Name) Then ; Ask whether to merge or overwrite Else ; Whatever you want here EndIf EndSwitch WEndI recommend my ExtMsgBox UDF to create a MsgBox type dialog with the buttons named as you wish - look in my sig below. All clear? 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
dixonpete Posted October 20, 2011 Author Posted October 20, 2011 (edited) Thanks, but doesn't your example still rely on a separate button being pushed? I could do that but it seems more intuitive in my application to have the validation done as the user presses ENTER to leave the field, getting feedback as they go. That would require field level validation and I'm not seeing that in the docs. Edited October 20, 2011 by dixonpete
Moderators Melba23 Posted October 20, 2011 Moderators Posted October 20, 2011 dixonpete, it seems more intuitive in my application to have the validation done as the user presses ENTER to leave the fieldSorry, that requirement was not clear. Just trap the input in the GUIGetMsg loop: #include <GUIConstantsEx.au3> $sExt = ".fil" ; We will force the new name to have this extension reqardless of what the user adds or omits $hGUI = GUICreate("Enter a name for the database", 320,120) $hName = GUICtrlCreateInput ( "", 10, 20, 300, 20) GuiSetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hName $sNew_Name = GUICtrlRead($hName) If $sNew_Name Then ; Force the correct extension If Not StringRegExp($sNew_Name, ".*\" & $sExt) Then $sNew_Name = StringRegExpReplace($sNew_Name, "^.*\\|\..*$", "") & $sExt EndIf ; Display it to show it works ConsoleWrite($sNew_Name & @CRLF) ; See if the file exists If FileExists($sNew_Name) Then ; Ask whether to merge or overwrite Else ; Whatever you want here EndIf EndIf EndSwitch WEnd 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
dixonpete Posted October 20, 2011 Author Posted October 20, 2011 Ah, ok. For some reason I didn't consider that input text boxes could be included in polling ( and validated) like any other GUI object.
Moderators Melba23 Posted October 20, 2011 Moderators Posted October 20, 2011 dixonpete,Inputs are a little special in that regard - you have to have entered at least one character for the input to action on ENTER. If it stays empty you do not get an event triggered as you can see here:#include <GUIConstantsEx.au3> $sExt = ".fil" ; We will force the new name to have this extension reqardless of what the user adds or omits $hGUI = GUICreate("Enter a name for the database", 320,120) $hName = GUICtrlCreateInput ( "", 10, 20, 300, 20) GuiSetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hName $sNew_Name = GUICtrlRead($hName) If $sNew_Name Then ; Force the correct extension If Not StringRegExp($sNew_Name, ".*\" & $sExt) Then $sNew_Name = StringRegExpReplace($sNew_Name, "^.*\\|\..*$", "") & $sExt EndIf ; Display it to show it works ConsoleWrite($sNew_Name & @CRLF) ; See if the file exists If FileExists($sNew_Name) Then ; Ask whether to merge or overwrite Else ; Whatever you want here EndIf Else ConsoleWrite("No input entry!" & @CRLF) EndIf EndSwitch WEndNote that once the input has had something entered it will fire even if you backspace the entry and leave the input empty. But you get no return if the input has had no data entered at all. To get over that problem I usually use an Accelerator key like this:expandcollapse popup#include <GUIConstantsEx.au3> $sExt = ".fil" ; We will force the new name to have this extension reqardless of what the user adds or omits $hGUI = GUICreate("Enter a name for the database", 320,120) $hName = GUICtrlCreateInput ( "", 10, 20, 300, 20) ; Create dummy control ; <<<<<<<<<<<<<<<<<<<<<<<< $hDummy = GUICtrlCreateDummy() GuiSetState(@SW_SHOW) ; Set accelerator for ENTER to action the dummy control ; <<<<<<<<<<<<<<<<<<<<<<<< Global $aAccelKeys[1][2]=[["{ENTER}", $hDummy]] GUISetAccelerators($aAccelKeys) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE Exit Case $hDummy $sNew_Name = GUICtrlRead($hName) If $sNew_Name Then ; Force the correct extension If Not StringRegExp($sNew_Name, ".*\" & $sExt) Then $sNew_Name = StringRegExpReplace($sNew_Name, "^.*\\|\..*$", "") & $sExt EndIf ; Display it to show it works ConsoleWrite($sNew_Name & @CRLF) ; See if the file exists If FileExists($sNew_Name) Then ; Ask whether to merge or overwrite Else ; Whatever you want here EndIf Else ConsoleWrite("No input entry!" & @CRLF) EndIf EndSwitch WEndAll clear? 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
dixonpete Posted October 20, 2011 Author Posted October 20, 2011 Getting there. Some new ideas in there for me and enough I think to get the task done when I get back to it next week. Appreciate the help.
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