Jump to content

Recommended Posts

Posted
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.
Posted

Search for RestrictControlRegExp.

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

  • Moderators
Posted

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? :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted

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? :graduated:

M23

  • Moderators
Posted

dixonpete,

That is trivial: :graduated:

#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
WEnd

I 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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Posted (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 by dixonpete
  • Moderators
Posted

dixonpete,

it seems more intuitive in my application to have the validation done as the user presses ENTER to leave the field

Sorry, that requirement was not clear. Just trap the input in the GUIGetMsg loop: :graduated:

#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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

  • Moderators
Posted

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
WEnd

Note 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:

#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
WEnd

All clear? :graduated:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...