Sign in to follow this  
Followers 0
BryonR

Line feed = button press

9 posts in this topic

I'm using a barcode scanner that will scan a numnber then do a line feed. Once that line feed is done I want it to click ok on the Autoit GUI.

Should be simple, its just a friday.

Case $Msg = $OK or @CRLF

Share this post


Link to post
Share on other sites



Some code will definitely help here ...


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Below is the full code that I have.

#include <GUIConstants.au3>

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Portable Charge Program", 330, 209, 193, 125)
$Label1 = GUICtrlCreateLabel("Scan Exam Barcode", 16, 56, 159, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Bookman Old Style")
$mtbarcode = GUICtrlCreateInput("", 24, 80, 201, 21)
$OK = GUICtrlCreateButton("OK", 16, 152, 113, 33, 0)
$Exit = GUICtrlCreateButton("Exit", 184, 152, 97, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $Msg = GUIGetMsg()
    Select
            
            Case $Msg = $GUI_EVENT_CLOSE Or $Msg = $Exit
                ExitLoop
            Case $Msg = $OK;or @CRLF
                    If StringStripWS(GuiCtrlRead($mtbarcode), 8) = "" Then
                        MsgBox(16, "Required", "Please fill out all fields or EXIT the program")
                            ContinueLoop
                    EndIf
                    
                if fileexists("c:\temp") then
                    fileinstall("I:\speedtest\connect.ini", "c:\temp\connect.ini", 1)
                Else
                    DirCreate("c:\temp")
                    fileinstall("I:\speedtest\connect.ini", "c:\temp\connect.ini", 1)
                EndIf
            ; ************Database write*****************
            $reqnumber = GUICtrlRead($mtbarcode)
            $t = (@hour & ":" & @min)
            $d = (@mon & "/" & @mday & "/" & @year & " ")
            $file = FileOpen("c:\temp\connect.vbs", 2)
            $db = IniRead("c:\temp\connect.ini", "Examnumber", "Full Database Path", "")
            $table = IniRead("c:\temp\connect.ini", "Examnumber", "Table Name", "")
            FileWriteLine($file, 'Dim adoCon, rsAddInfo, strSQL')
            FileWriteLine($file, 'Set adoCon = CreateObject("ADODB.Connection")')
            FileWriteLine($file, 'adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=' & $db & '"')
            FileWriteLine($file, 'Set rsAddInfo = CreateObject("ADODB.Recordset")')
            FileWriteLine($file, 'strSQL = "SELECT * FROM ' & $table & ';"')
            FileWriteLine($file, 'rsAddInfo.CursorType = 2')
            FileWriteLine($file, 'rsAddInfo.LockType = 3')
            FileWriteLine($file, 'rsAddInfo.Open strSQL, adoCon')
            FileWriteLine($file, 'rsAddInfo.AddNew')
            FileWriteLine($file, 'rsAddInfo.Fields("examnum") = ' & '"' & $reqnumber & '"')
            FileWriteLine($file, 'rsAddInfo.Fields("datetime") = ' & '"' & $d & $t & '"')
            FileWriteLine($file, 'rsAddInfo.Update')
            FileWriteLine($file, 'rsAddInfo.Close')
            FileWriteLine($file, 'Set rsAddInfo = Nothing')
            FileWriteLine($file, 'Set adoCon = Nothing')
            FileWriteLine($file, 'Set strSQL = Nothing')
        ; Close our .vbs file
            FileClose($file)
        ; Call Wscript.exe to run the .vbs file
            RunWait("Wscript.exe " & '"' & "c:\temp\connect.vbs" & '"')
        ; ***********Datebase compelete wite************
        ; Delete our .vbs file when done
            FileDelete("c:\temp\connect.vbs")
            FileDelete("c:\temp\connect.ini")
            guictrlsetdata($mtbarcode,"")
                    Send("{tab}{tab}")
                    ContinueLoop
                    ExitLoop
    EndSelect
            WEnd
            GUIDelete()
            Exit

Thanks! Bryon

Share this post


Link to post
Share on other sites

So what's it not doing that you want it to do, I think "if fileexists("c:\temp") then" should be "if DirGetSize("c:\temp") = -1 then". And I don't see where $mtbarcode is defined.


Giggity

Share this post


Link to post
Share on other sites

When a barcode is scanned with a scanner it does a line feed after each scan. What i'm looking for is once it does that line feed is to click OK.

-Bryon

Share this post


Link to post
Share on other sites

Some info is missing here; I don't see how your barcode ends up on that inputbox. Is your scanner software sending it directly to that control?

What I can think of is: you need to continuously monitor your inputbox content, once a line feed is detected there it can start the function associated with "OK" button and clear the inputbox content once the data is processed.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

Well that would make it so if he hit enter it would run right? If the barcodes are all the same length you could do a charcount and have it call the function when the charcount is met. If they are of different lengths, you could have it read the line every 5 seconds or so and if the line is the same after 5 seconds (and not "" of course), then it knows the code is in there, then have it call the function. If I'm understanding the issue that is.


Giggity

Share this post


Link to post
Share on other sites

Maybe something like then?

#include <GUIConstants.au3>
$timestamp = TimerInit ()
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Portable Charge Program", 330, 209, 193, 125)
$Label1 = GUICtrlCreateLabel("Scan Exam Barcode", 16, 56, 159, 22)
GUICtrlSetFont(-1, 11, 800, 0, "Bookman Old Style")
$mtbarcode = GUICtrlCreateInput("", 24, 80, 201, 21)
$OK = GUICtrlCreateButton("OK", 16, 152, 113, 33, 0)
$Exit = GUICtrlCreateButton("Exit", 184, 152, 97, 33, 0)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $Msg = GUIGetMsg()
    $buffer = TimerDiff ($timestamp)
    Select
            Case $Msg = $GUI_EVENT_CLOSE Or $Msg = $Exit
                ExitLoop
            Case $buffer >= 50
                $timestamp = TimerInit ()
                If StringInStr (GUICtrlRead ($mtbarcode), @CRLF) Then
                ;Do what you need to.
                EndIf
    EndSelect
WEnd

I think that the fact that it's a SINGLE line input may have a factor in it. See about experiment with a style to get a edit control looking like your input box.

Cheers,

Brett

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