Sign in to follow this  
Followers 0
MirnesC2

input boxes question

7 posts in this topic

How do I limit what is being put into an input box? For example if I only wanted numbers in one input box, only letters in one input box, no symbols, maximum/minimum characters, and etc. ?

Share this post


Link to post
Share on other sites



For numbers you can use $ES_NUMBER, I'm not sure how to limit other stuff though.


The Wheel of Time turns, and Ages come and pass, leaving memories that become legend. Legend fades to myth, and even myth is long forgotten when the Age that gave it birth comes again.

Share this post


Link to post
Share on other sites

I can't help but think there is a much easier way to do this, but here are two examples from one very tired person, but they should work.

#include <GUIConstantsEx.au3>
$GUI = GUICreate("GUI", 300, 70)
$Input1 = GUICtrlCreateInput("123Input123", 10, 10, 230, 20)
$Input2 = GUICtrlCreateInput("123Input123", 10, 40, 230, 20)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    AlphaOnly1($Input1, $GUI)
    AlphaOnly2($Input2, $GUI)
    Sleep(10)
WEnd


Func AlphaOnly1($ctrl, $fgui) ; Waits until the control no longer has focus
    $control = ControlGetFocus($fgui)
    If Not IsDeclared("focus") Then Global $focus = 0
    If ControlGetHandle($fgui, '', $control) = GUICtrlGetHandle($ctrl) Then
        $focus = 1
    EndIf
    If $focus = 1 And ControlGetHandle($fgui, '', $control) <> GUICtrlGetHandle($ctrl) Then
        $focus = 0
        $data = GUICtrlRead($ctrl)
        $reg = StringRegExp($data, '[[:alpha:] ]', 3)
        $ret = ''
        For $a = 0 To UBound($reg) - 1
            $ret &= $reg[$a]
        Next
        If $data <> $ret Then
            GUICtrlSetData($ctrl, $ret)
            Return 1
        EndIf
    EndIf
    Return 0
EndFunc   ;==>AlphaOnly

Func AlphaOnly2($ctrl, $fgui) ; Always checking. Will move cursor to end of string if it changes the data
    $data = GUICtrlRead($ctrl)
    $reg = StringRegExp($data, '[[:alpha:] ]', 3)
    $ret = ''
    For $a = 0 To UBound($reg) - 1
        $ret &= $reg[$a]
    Next
    If $data <> $ret Then
        GUICtrlSetData($ctrl, $ret)
        Return 1
    EndIf
    Return 0
EndFunc   ;==>AlphaOnly2

Share this post


Link to post
Share on other sites

Wow, that's more code than my entre program itself. Lol.

Share this post


Link to post
Share on other sites

Wow, that's more code than my entre program itself. Lol.

Haha, yeah, I cannot help but think there is an easier obvious way to do this, but I can't seem to think of one... hopefully somebody will come by and show us a couple line example of how to accomplish this.

Share this post


Link to post
Share on other sites

Yea, lol. I think Hawkwing might be on to something easier.

Share this post


Link to post
Share on other sites

Well $ES_NUMBER is the only limiting factor I see listed in the help file though... so I don't know if there will be an option for any other limiting factor.

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0