narf3333

Execute function as soon as text is present in a input box

8 posts in this topic

#1 ·  Posted (edited)

Hello,

 

I am somewhat new to AutoIt and I am trying to develop an application to track check-ins for a local Flea Market I help run.  I already wrote a application that updates my SQL database by updating a maxnum value by one, logging the users usernum and logging the current day/time.  Problem is that I need to manually press a 'Submit' for it to work.  When we actually use this at the gate to the Flea Market the computer running the application is going to be inside a trailer and we plan on having a wireless barcode scanner outside scanning the barcodes on the membership cards.  I need to somehow have this application realize that text is present in the input box and automatically submit it without me having to press submit.

 

Here is what I have so far which does work if I manually press the 'Test' button.

Func MainGUI()
      Local $hMainGUI = GUICreate("Flea Market", 300, 100)
      GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
      $UserNum = GUICtrlCreateInput("", 50, 40, 200, 20)

      Local $iAddButton = GUICtrlCreateButton("Test", 50, 70, 60)
      GUICtrlSetOnEvent($iAddButton, "_CheckIn")

      GUISetState(@SW_SHOW, $hMainGUI)

      While 1
         Sleep(100) ; Sleep to reduce CPU usage
      WEnd
   EndFunc

   Func CLOSEButton()
      MsgBox(0, "Flea Market", "You selected CLOSE! Exiting...")
      Exit
   EndFunc

Func _CheckIn ($conn)
      Local $sQueryMaxNum, $sCurrentMaxNum, $sQueryUpdateVisitMaxNum, $adCN, $sString1, $sString2
      Local $sQueryUpdateVisitMaxNum = "UPDATE dbo.admin SET visitmaxnum = visitmaxnum + 1 where item = 1"
      $sString1 = GUICtrlRead($UserNum)
      $adCN = ObjCreate ("ADODB.Connection")
      $adCN.Open ($conn)
      $sQueryMaxNum = ObjCreate( "ADODB.RecordSet" )
      $sQueryMaxNum.Open( "SELECT * from dbo.admin", $adCN )
      $sCurrentMaxNum = $sQueryMaxNum.Fields( "visitmaxnum" ).Value
      $sString2 = "insert into dbo.visit (item, usernum, datevisited) values ('" & $sCurrentMaxNum & "', '" & $sString1 & "', '" & _DateTimeFormat(_NowCalc(), 0) & "')"
      $adCN.Execute($sString2)
      $adCN.Execute($sQueryUpdateVisitMaxNum)
      $adCN.Close
      GUICtrlSetData($UserNum, "")
   EndFunc
Edited by Melba23
Added code tags

Share this post


Link to post
Share on other sites



narf3333,

Welcome to the AutoIt forums.

Will the input fill up immediately when you scan the membership cards or will there be a lag as the characters appear?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

There will be a slight delay as the handheld barcode scanner sends the barcode value.  I would want the entire barcode to fully type in the box before it auto submits.

Thanks

Share this post


Link to post
Share on other sites

Melba23,

The reason I asked is that it is easy to look for changes in the input and if everything was entered at once then we do not need to delay the activation. As it is we will have to wait until there is no further change after a short period. So something like this should work:

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

Opt("GUIOnEventMode", 1)

Global $UserNum, $sSaved_Content = ""

MainGUI()

; Run an Adlib function every 250ms
AdlibRegister("_Check_Input")

While 1
    Sleep(10) ; Always keep the idle loop OUTSIDE a function <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
WEnd

Func MainGUI()
    $hMainGUI = GUICreate("Flea Market", 300, 100)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
    $UserNum = GUICtrlCreateInput("", 50, 40, 200, 20)

    Local $iAddButton = GUICtrlCreateButton("Add number", 50, 70, 60)
    GUICtrlSetOnEvent($iAddButton, "_Add_Number")

    GUISetState(@SW_SHOW, $hMainGUI)

EndFunc   ;==>MainGUI

Func CLOSEButton()
    MsgBox(0, "Flea Market", "You selected CLOSE! Exiting...")
    Exit
EndFunc   ;==>CLOSEButton

Func _Add_Number()
    GUICtrlSetState($UserNum, $GUI_FOCUS)
    For $i = 0 To 9
        Send($i)
    Next

EndFunc   ;==>_CheckIn

Func _Check_Input()

    ; Read input
    $sContent = GUICtrlRead($UserNum)
    ; If there is content
    If $sContent Then
        If $sContent <> $sSaved_Content Then
            ; Save changing content
            $sSaved_Content = $sContent
        Else
            ; All finished

            ; Do your stuff here
            MsgBox($MB_SYSTEMMODAL, "Read", GUICtrlRead($UserNum))

            ; Clear up ready for the next one
            $sSaved_Content = ""
            GUICtrlSetData($UserNum, "")
        EndIf
    EndIf

EndFunc
Please ask if you have any questions.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Can you hit Enter on the computer, that the barcode scanner is connected to, that will hit the Submit for you? If so you can probably program the scanner to append a CR (carriage return) to the end of the scanned code. I haven't run into a barcode scanner that doesn't have that capability.

Edited by BrewManNH

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

BrewManNH,

That would certainly ease the task considerably.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

Share this post


Link to post
Share on other sites

Melba23,

The reason I asked is that it is easy to look for changes in the input and if everything was entered at once then we do not need to delay the activation. As it is we will have to wait until there is no further change after a short period. So something like this should work:

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

Opt("GUIOnEventMode", 1)

Global $UserNum, $sSaved_Content = ""

MainGUI()

; Run an Adlib function every 250ms
AdlibRegister("_Check_Input")

While 1
    Sleep(10) ; Always keep the idle loop OUTSIDE a function <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
WEnd

Func MainGUI()
    $hMainGUI = GUICreate("Flea Market", 300, 100)
    GUISetOnEvent($GUI_EVENT_CLOSE, "CLOSEButton")
    $UserNum = GUICtrlCreateInput("", 50, 40, 200, 20)

    Local $iAddButton = GUICtrlCreateButton("Add number", 50, 70, 60)
    GUICtrlSetOnEvent($iAddButton, "_Add_Number")

    GUISetState(@SW_SHOW, $hMainGUI)

EndFunc   ;==>MainGUI

Func CLOSEButton()
    MsgBox(0, "Flea Market", "You selected CLOSE! Exiting...")
    Exit
EndFunc   ;==>CLOSEButton

Func _Add_Number()
    GUICtrlSetState($UserNum, $GUI_FOCUS)
    For $i = 0 To 9
        Send($i)
    Next

EndFunc   ;==>_CheckIn

Func _Check_Input()

    ; Read input
    $sContent = GUICtrlRead($UserNum)
    ; If there is content
    If $sContent Then
        If $sContent <> $sSaved_Content Then
            ; Save changing content
            $sSaved_Content = $sContent
        Else
            ; All finished

            ; Do your stuff here
            MsgBox($MB_SYSTEMMODAL, "Read", GUICtrlRead($UserNum))

            ; Clear up ready for the next one
            $sSaved_Content = ""
            GUICtrlSetData($UserNum, "")
        EndIf
    EndIf

EndFunc
Please ask if you have any questions.

M23

 

 

This worked perfectly.  I have been trying to figure this last part out since Monday.  Thank you so much!

Share this post


Link to post
Share on other sites

narf3333,

Glad I could help.

But when you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - I know what I wrote and it just pads the thread unnecessarily.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______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

 

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