Sign in to follow this  
Followers 0
jchd

Auto entry of simple-line edit control

5 posts in this topic

I'm having a hard time searching MSDN to find a way to perform the following action. Simple background: I have barcode input controls which only accept 13 characters and need check-digit validation before further processing. I need to avoid requiring user hitting TAB to switch to next field.

In a size-limited single-line edit control (13 characters exactly in this case) I whish to automatically asociate (and launch on edit full "event") a custom validation function (pass/fail)

Upon validation I whish to set focus to another field.

I didn't find a message denoting "maximum size of edit control reached" so I don't have an event to rely on.

Is there a way (AutoIt or DllCall) to do this, lest switch to non-event message processing and intercepting every character entered?


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Something like this ?

#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
Opt("GUIOnEventMode", 1)
$hTest = GUICreate("Test")
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
Local $hInput[5], $iTop = 10, $bInputsComplete = False
For $i = 0 To 4 Step 1
    $hInput[$i] = GUICtrlCreateInput("", 10, $iTop, 121, 21, $ES_NUMBER)
    GUICtrlSetState(-1, $GUI_DISABLE)
    GUICtrlSetLimit(-1, 13)
    $iTop += 30
Next
GUICtrlSetState($hInput[0], $GUI_ENABLE)

GUISetState(@SW_SHOW)

$i = 0
While 1
    If WinActive($hTest) And Not $bInputsComplete Then
        $sReadInput = GUICtrlRead($hInput[$i])
        If StringLen($sReadInput) >= 13 Then
            If StringLen($sReadInput) > 13 Then ; just incase its slow at grabing the 13 char count
                $sReadInput = StringTrimLeft($sReadInput, 13)
                GUICtrlSetData($hInput[$i], $sReadInput)
            EndIf
            If _CheckValidation($sReadInput) Then
                If $i < 4 Then
                    GUICtrlSetState($hInput[$i], $GUI_DISABLE)
                    $i += 1
                    GUICtrlSetState($hInput[$i], $GUI_ENABLE)
                    GUICtrlSetState($hInput[$i], $GUI_FOCUS)
                Else
                    GUICtrlSetState($hInput[$i], $GUI_DISABLE)
                    $bInputsComplete = True
                EndIf
            Else
                MsgBox(0, "Warning!", "Sorry invalid entry please try again", 0, WinGetHandle($hTest))
                GUICtrlSetData($hInput[$i], "")
            EndIf
        EndIf
    EndIf
    Sleep(100)
WEnd


Func _CheckValidation($sString)
    $iReturn = MsgBox(4, "Check validation", "is " & $sString & " a valid entry")
    If $iReturn = 6 Then
        Return True
    Else
        Return False
    EndIf
EndFunc   ;==>_CheckValidation

Func Form1Close()
    Exit
EndFunc   ;==>Form1Close

Edit - i see why it was allowing entry to go over 13 now i had the limit set on the first enabled input only :) , moved it to loop of input creation but left in the over 13 length checker anyway :(

Edited by Yoriz

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites

Thanks for your input Yoriz.

So I'm not search-autist, it seems there is no built-in mecanism to mimic the Bell signal at end of line for typewriters ... talk about modernity :(

This approach requires I bring back lots of code into the main loop, which I'd like to stay away of. If I get it right it's that or install a character trap in a WM_Notify and filter for active control and conditions. All in all I prefer that latter approach.

Warm thanks.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

In the helpfile example of udf _GUICtrlEdit_Create '$EN_MAXTEXT' poped out at me, i grabbed the needed parts out of the code as i dont fully understand all that GUIRegisterMsg stuff yet but $EN_MAXTEXT is close to what you wanted i think but the only problem is the msg is only created when you try and enter something past the limit so if you have 13 chars limit and try and enter a 14th. I used $EN_CHANGE to actually grab the 13th char entry, a shame $EN_MAXTEXT doesnt actually flag up when the last char is reached.

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

Global $iLimitLength = 13
Opt("GUIOnEventMode", 1)
$Form1 = GUICreate("Form1", 305, 206, -1, -1)
GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close")
$Input1 = GUICtrlCreateInput("", 8, 8, 121, 21)
GUICtrlSetLimit(-1, $iLimitLength)
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
GUISetState(@SW_SHOW)

While 1
    Sleep(100)
WEnd

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hWndFrom, $iIDFrom, $iCode, $hWndEdit
    $hInput1 = GUICtrlGetHandle($Input1)
    $hWndFrom = $ilParam
    $iIDFrom = _WinAPI_LoWord($iwParam)
    $iCode = _WinAPI_HiWord($iwParam)
    Switch $hWndFrom
        Case $hInput1, $hWndEdit
            Switch $iCode
                Case $EN_MAXTEXT
                    MsgBox(0, "", "exceded max size")
                Case $EN_CHANGE
                    If StringLen(GUICtrlRead($Input1)) = $iLimitLength Then MsgBox(0, "", "reached max size")
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>_WM_COMMAND


Func Form1Close()
    Exit
EndFunc   ;==>Form1Close

GDIPlusDispose - A modified version of GDIPlus that auto disposes of its own objects before shutdown of the Dll using the same function Syntax as the original.EzMySql UDF - Use MySql Databases with autoit with syntax similar to SQLite UDF.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Oh sorry, I didn't update that post to reflect what I did. Might serve others as well someday. So here it is, completely unabridged.

Func WM_COMMAND($hWnd, $iMsg, $iwParam)
    #forceref $hWnd, $iMsg, $iwParam
    Local $iIDFrom = BitAND($iwParam, 0x0000FFFF)
    Local $iCode = BitShift($iwParam, 16)
    Switch $iIDFrom
        Case $ibNumColis    ;; the control ID
            Switch $iCode
                Case $EN_CHANGE
                    If StringLen(GUICtrlRead($ibNumColis)) >= 13 Then _ibNumColisChange()   ; if length reached, invoke validation
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

It turned out that the validation function had some time ago to deal with wrongly manufactured forms with barcodes having two extra zeroes embedded. Needless to say that broke the check-digit computation, but that why I deal with length >= 13 and not only = 13.

I apologize again for leaving you continue dig the hole alona while I was already elsewhere: I should have signaled end of quest here.

BTW I see we both came up with essentially the same code, no wonder !

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

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