Sign in to follow this  
Followers 0
sankar18

Textbox validation

8 posts in this topic

Hi Everyone, I want to validate the textbox contain only floating point values which always in "xxx.xx" formate 3 digit and after "." two digit. i try this Global $iicd1 = GUICtrlCreateInput("", 208, 310, 60, 20,$ES_Number) GUICtrlSetLimit(-1, 6) but didn't get "." any one please look on this and do the needful thank in advance

Share this post


Link to post
Share on other sites



I searched the forum for a similar example and found one by martin and modifed it to perform about how you would like. The only problem with this code is backspacing to delete the "." does not work. I'm trying to figure it out.

Here's what I have so far:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <EditConstants.au3>

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

$gui = GUICreate("Gui", 300, 100)

$IP = GUICtrlCreateInput("", 10, 40, 200, 22, $ES_NUMBER)
GUICtrlSetLimit($IP, 6)

GUISetState()


While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    If $nID = $IP Then
        $hCtrl = $lParam
        If $nNotifyCode = $EN_CHANGE Then
            $txt = GUICtrlRead($IP)
                If StringLen($txt) = 3 Then
                    $newtxt = $txt & "."
                    GUICtrlSetData($IP, $newtxt)
                EndIf
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

I think this will work:

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <editconstants.au3>
#include <Misc.au3>

GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")

$gui = GUICreate("Gui", 300, 100)

$IP = GUICtrlCreateInput("", 10, 40, 200, 22, $ES_NUMBER)
GUICtrlSetLimit($IP, 6)

GUISetState()


While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE Then ExitLoop
WEnd

Func WM_COMMAND($hWnd, $msg, $wParam, $lParam)
    $nNotifyCode = BitShift($wParam, 16)
    $nID = BitAND($wParam, 0x0000FFFF)
    If $nID = $IP Then
        $hCtrl = $lParam
        If $nNotifyCode = $EN_CHANGE Then
            $txt = GUICtrlRead($IP)
                Local $hDLL = DllOpen("user32.dll")

                If _IsPressed("08", $hDLL) AND StringLen($txt) = 4 Then
                    $newtxt = StringTrimRight($txt, 1)
                    GUICtrlSetData($IP, $newtxt)
                ElseIf StringLen($txt) = 3 Then
                    $newtxt = $txt & "."
                    GUICtrlSetData($IP, $newtxt)
                EndIf
        EndIf
    EndIf
    Return $GUI_RUNDEFMSG
EndFunc

RAID Calculator | Software Installer

The truth has been suppressed since the dawn of time.

Share this post


Link to post
Share on other sites

Its working.  :thumbsup: 

 

 Thanks

Share this post


Link to post
Share on other sites

The regular expression should work. I didn't try abberration's code, but I think it's much easier to allow the user to type whatever they like and only validate the input after they click the Okay button. Good luck with it. :)

Share this post


Link to post
Share on other sites

Awesome!!!!!!!!!!! 

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