Sign in to follow this  
Followers 0
MattHiggs

(solved)Barcode reading script

2 posts in this topic

#1 ·  Posted (edited)

Nevermind.  I'm an idiot.

 

Hello all.  I had previously written a post about inputting data received from a barcode scanner into an excel file

  I have actually found the time to write the thing, and I am getting some unexpected results.  I am taking the input received from the Bar code scanner and inputting it into a ".txt" file, which I then use as the source to create a new workbook.  However, it would seem that, somehow, the information being input into the text file is not valid, and I can't figure it out for the life of me.  No mater what is scanned, the input is always the number 3.  Here is my code and attached is the txt file.  Please help me out.

#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1033
#AutoIt3Wrapper_Add_Constants=n
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
; *** Start added by AutoIt3Wrapper ***
#include <ExcelConstants.au3>
#include <FileConstants.au3>
#include <MsgBoxConstants.au3>
; *** End added by AutoIt3Wrapper ***
#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.15.0 (Beta)
 Author:         myName

 Script Function:
    Template AutoIt script.

#ce ----------------------------------------------------------------------------

; Script Start - Add your code below here
#include <Constants.au3>
#include <Excel.au3>
Local $oExcel = _Excel_Open(Default, Default, Default, Default, True)
opennow ()
If FileExists ( @AppDataDir & "\excelinput.txt" ) Then
    Do
        FileDelete ( @AppDataDir & "\excelinput.txt" )
    Until Not FileExists ( @AppDataDir & "\excelinput.txt" )
EndIf
$setIMEI = True
$row = 0
$name1 = ""
$file = FileOpen ( @AppDataDir & "\excelinput.txt", $FO_APPEND )
FileWriteLine ( $file, "Text1|Text2" )
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=C:\Users\William Higgs\OneDrive\always script\form\Excel barcode scanner.kxf
$Form1 = GUICreate("Excel Barcode input", 420, 435, 192, 124)
GUISetCursor (0)
$Input1 = GUICtrlCreateInput("", 48, 64, 305, 21, BitOR($GUI_SS_DEFAULT_INPUT,$ES_NOHIDESEL))
$ListView1 = GUICtrlCreateListView("IMEI|Serial number", 56, 160, 300, 193)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 0, 150)
GUICtrlSendMsg(-1, $LVM_SETCOLUMNWIDTH, 1, 150)
$Button1 = GUICtrlCreateButton("Send to Excel", 168, 376, 89, 33)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Input1
            If $setIMEI = True Then
                FileWrite ( $file, $Input1 & "|" )
                $setIMEI = False
                GUICtrlSetData($Input1,'')
            ElseIf $setIMEI = False Then
                FileWriteLine ( $file, $Input1 )
                $setIMEI = True
                GUICtrlSetData($Input1,'')
            Else
                SetError ( 2 )
            EndIf
        Case $ListView1
        Case $Button1
            FileClose ( $file )
            Local $aField1[2] = [1, $xlGeneralFormat]
            Local $aField2[2] = [2, $xlGeneralFormat]
            Local $aFieldInfo[2] = [$aField1, $aField2]
            If $row = 0 Then
                $oBook = _Excel_BookOpenText ( $oExcel, @AppDataDir & "\excelinput.txt", Default, $xlDelimited, Default, True, "|", $aFieldInfo )
            Else
                $oBook = _Excel_BookOpenText ( $oExcel, @AppDataDir & "\excelinput.txt", $row, $xlDelimited, Default, True, "|", $aFieldInfo )
            EndIf
            If $name1 == "" Then
                _Excel_BookSave ( $oBook )
            Else
                _Excel_BookSaveAs ( $oBook, $name1 )
            EndIf


    EndSwitch
WEnd


Func opennow()
#Region --- CodeWizard generated code Start ---


;MsgBox features: Title=Yes, Text=Yes, Buttons=Yes and No, Default Button=Second, Icon=None
If Not IsDeclared("iMsgBoxAnswer") Then Local $iMsgBoxAnswer
$iMsgBoxAnswer = MsgBox($MB_YESNO + $MB_DEFBUTTON2,"Edit existing document","Do you have a exsisting document you want to edit?  Select no if you want to create new.")
Select
    Case $iMsgBoxAnswer = $IDYES
        $name = FileOpenDialog ( "Choose your file", @MyDocumentsDir & "\", "Excel workbooks (*.xlsx;*.xlsm;*.xls)" )
        If $name == "" Then
            opennow()
        Else
            #Region --- CodeWizard generated code Start ---
;InputBox features: Title=Yes, Prompt=Yes, Default Text=No, Mandatory
If Not IsDeclared("sInputBoxAnswer") Then Local $sInputBoxAnswer
$sInputBoxAnswer = InputBox("Start Row","Open your excel document and determine at which row you would like the data to start being written, so none of your previous data gets overwritten",""," M","-1","-1","-1","-1")
Select
    Case @Error = 0 And StringIsDigit ( $sInputBoxAnswer ) = 1 ;OK - The string returned is valid
        $row = $sInputBoxAnswer
    Case @Error = 1 ;The Cancel button was pushed
        Exit
    Case Else ;The InputBox failed to open
        Exit
EndSelect
#EndRegion --- CodeWizard generated code End ---

            ;$oWorkbook = _Excel_BookOpen ( $oExcel, $name )
        EndIf


    Case $iMsgBoxAnswer = $IDNO
        $name1 = FileSaveDialog ( "Where would you like to save your new document?", @MyDocumentsDir, "Excel workbooks (*.xlsx;*.xlsm;*.xls)" )
        ;$oWorkbook = _Excel_BookNew ( $oExcel )

EndSelect
#EndRegion --- CodeWizard generated code End ---
EndFunc

 

excelinput.txt

Edited by MattHiggs

Share this post


Link to post
Share on other sites



You must use GuiCtrlRead:

FileWrite ($file, GUICtrlRead($Input1) & "|" )

without you are writing the ControlID in file.

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