Jump to content

Recommended Posts

Posted

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

Posted

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
Posted

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
Posted

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. :)

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