event on scaning barcode

hi ,
i am using vb.net 2003 and i want to scan barcodes with the scaner i want if the scaner completes the scaning doesn't matter what the length is the next textbox is focused i tried it on different events but could not find the proper event 

can any body help me 

best regards

ali shah


Answer this question

event on scaning barcode

  • KevinJC

    hi thanz for ur giudeness i have solved the problem by making a new window form and what i did that i caliberated the fields by the length of the barcodes of specific lot and also imei and pin no etc and with the help of global variable u used the lenghts for the specific textboxes in my original form it is working now 

    now i want to know that can i email crystal report by clicking the button from my form or when i m viewing the crystal report 

    alway looking for your favour 

    thanx 

    ali

  • KristiLM

    What kind of barcode scanner is it   Serial or Keyboard-Wedge

    Either way, the logic of the problem is the same.  Using a barcode reader is the same as entering data from the keyboard as far as the computer is concerned.  The Textbox cannot know when you are done typing.  That's why we have an "Enter" key.  The same goes for barcodes.  You need a "End" character in the barcode, or the data in the barcode needs to be a fixed length.  You want the Textbox.TextChanged event to watch for either the "end" character to be scanned, or for the length of characters inputed to reach a specified value.  Then you can set focus to the next textbox.

    Actually, if you just embed a "Tab" character at the end of the barcode that will advance focus to the next control in the tab order (providing you're using a keyboard wedge).

    If you're reading someone else's barcodes and you can't design them, you might be best to just let your user hit the spacebar (or some key) to advance to the next textbox.

  • Jeffrey Odell

    Hi,
    thanx for your guideness actually the problem is that we are getting different products from different vendors and they have different length of barcodes so the length is not fixed.
    and for the end character every barcode as you know is coverd with *11212333* and the estaric is only the end character is it possible that we can tell our reader to read the ending * character and then focus to the next control 

    best regards ali shah

  • DotNetMonster

    ali,

    Please tell me what kind of barcode reader you are using...  Is it a serial (you use read from a COM port in code to get scanned values) or is it a keyboard wedge (it sits inline with the keyboard and emulates key presses)

    If it is serial, you have an event to work with every time the user scans; the keyboard wedge is harder...

    There are no standards for barcodes beyond the symbology used to create one.  The asteriks you speak of are just printed and probably not even encoded in the data.

    Since you are scanning barcodes created by others, you cannot use a termination character.  Now, on the other hand, you may be scanning fixed width codes and you just don't realize it.  The printed numbers beneath the barcode might be different lengths but the barcode itself may have padding to fix the length.

    Most barcode symbologies are defined by a fixed number of characters.  Encoded data that is shorter than the allotted data length is padded, or justified.  I would suggest that you find out what exactly you are scanning (most product barcoding is ruled by a symbology - consumer product id, shipping info, etc.) then look up the rules for that symbology on a site like www.barcodeisland.com.  That will tell you how many characters are in the barcode.

    I still think you'd be best to let your user hit a key on the keyboard to advance to the next field; or if they aren't near the keyboard, create your own "special" barcode that the app recognizes as a command to advance to the next field, post it near where they work, and let them scan it between each actual product scan.

  • Hybidder

    Ali,

    You're quite welcome for the help.  I'm glad I was able to do so.

    As for your future problems, I would really recommend that you continue to post your questions here.  Although I've been the one to help you recently, there are many other knowledgable users here and you could certainly ask a question that I don't have an answer for; or that someone else has a better answer for.  Also, this site is building quite a knowlege base and it only works if questions and answers are posted here.

    But, if you have a post that goes unanswered, I won't mind you contacting me directly.  You can email me using the username I post under at the domain: microplastics.com.  (sorry for being indirect, but I don't like to post my address in a manner that can be farmed).

    Good luck to you!

    rkimble

  • Freem0n

    hi Ian 

    actually the lenght of the barcodes is not fixed we are purchasing different products from different vendors and they have their own defined lenght 

    cheers 

    ali shah

  • AmandaJO

    hi dear 

    i need to export and email a crystal report i know that first i have to save it and then email it by attachment and in this way it is working but i want to do this in a single event means i want to give my user a single button and if the user clicks the button the report is first exported and then it attaches the saved file from the location and then email it 

    i have tried it but i am not succeeded here is my code 

    Private Sub btnexport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnexport.Click
            Dim strext As String
            Dim a As New DateTimePicker
            a.Value = Now
            Dim ddo As New CrystalDecisions.Shared.DiskFileDestinationOptions

            Try
                With Me.despatch1.ExportOptions
                    .ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.WordForWindows
                    strext = ".Doc"
                    .ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile



                    ddo.DiskFileName = Me.txtexportfilepath.Text + TextBox1.Text & a.Value & strext
                    .DestinationOptions = ddo


                End With

                Me.despatch1.Export()
                MessageBox.Show("Report Exported !")
            Catch excp As Exception
                MessageBox.Show(excp.Message)
            End Try


            Dim smtp As System.Web.Mail.SmtpMail
            Dim msg As New System.Web.Mail.MailMessage
            TextBox2.Text = Me.txtexportfilepath.Text + TextBox1.Text & a.Value & strext
            
            Dim atch As New System.Web.Mail.MailAttachment(TextBox2.Text)

            smtp.SmtpServer = "alctiserver.airlandata.com"
            msg.Attachments.Add(atch)

            msg.From = "ali.shah@airlandata.com"
            msg.To = "faizan.ahmed@airlandata.com;ali.shah@airlandata.com"
            msg.Subject = "This is the subject of the email"
            msg.Body = "This is the body of the email"
            Try
                smtp.Send(msg)
                MessageBox.Show("Your email has been successfully sent!")
                        Catch exp As Exception
                MessageBox.Show("The following problem occurred when attempting to " & _
                    "send your email: " & exp.Message, _
                    Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try

        End Sub

    here textbox1 contains the name of the supplier to which i have to email and 
     txtexportfilepath contains the directory to which i want to expoert my file 

    but it gives the error "invalid filename " i know that that attachmetn path can't find the specified path 

    i want to know that if there is any other way to do this in vb.net 

    regards
     
    ali 

  • hokial

    thanks rkimble 

    i can export my report now but the problems is that i don't wnat to give a browse button to my user to email the currently exported report i want it to export it on the certain path and then email it from that path without browsing it and for this 

    i have a textbox2 with textproperty ="
    another textbox named txtexportfilepath with textproperty = c:\reports\
    i have textbox1 which containes the name of the supplier to whome i have to email
    i have string named strext = ".Doc"
    i have another textbox3 with textproperty =" 

    and my export button exports the report  to this path

     ddo.DiskFileName = Me.txtexportfilepath.Text & TextBox1.Text & strext
                    .DestinationOptions = ddo
      plus i set the textxbox2 as 

    TextBox2.Text = TextBox2.Text & Me.txtexportfilepath.Text & TextBox1.Text & strext & TextBox3.Text
     
    the report is exported successfully to it's destination and the text in textbox2 is as 
    "c:\reports\BT-MOBILES.Doc"
    which is the same as the path of the current exported file 

    now i have another button to email this report 

    and the code is 

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim smtp As System.Web.Mail.SmtpMail
            Dim msg As New System.Web.Mail.MailMessage
            Dim str As String
            str = TextBox2.Text
            Dim atch As New System.Web.Mail.MailAttachment(str)

            smtp.SmtpServer = "alctiserver.airlandata.com"
            msg.Attachments.Add(atch)

            msg.From = "ali.shah@airlandata.com"
            msg.To = "faizan.ahmed@airlandata.com;ali.shah@airlandata.com"
            msg.Subject = "This is the subject of the email"
            msg.Body = "This is the body of the email"
            Try
                smtp.Send(msg)
                MessageBox.Show("Your email has been successfully sent!")
                '& _ "Email Send Status", MessageBoxButtons.OK, _ 
                'MessageBoxIcon.Information)
            Catch exp As Exception
                MessageBox.Show("The following problem occurred when attempting to " & _
                    "send your email: " & exp.Message, _
                    Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)
            End Try
        End Sub

    but when i press the button to email the report  it gives me the error message 

    An unhandled exception of type 'System.Web.HttpException' occurred in system.web.dll

    Additional information: Invalid mail attachment '"c:\reports\BT-MOBILES.Doc"'.

    but if i copy the text from textbox2 which is 
    "c:\reports\BT-MOBILES.Doc"
     and paste it in the place of str that is 

    Dim atch As New System.Web.Mail.MailAttachment("c:\reports\BT-MOBILES.Doc"
    )
    then it works it means that there is no problem with the path of the file but it is not working direclty and i want to email it direclty 

    is it possible 

    best regards

    ali shah

  • Kylelanson

    Could you not tell the textbox valuechanged event to move focus to another control if the character length is a certain value

    Cheers
    Ian

  • Clement Yuan

    The problem appears to be with the doublequotes (") in textboxes 2 and 3.  These are not necessary and will cause the path of the attachment to be invalid.

    Notice that when you first save your report, you are not using the double quotes in ddo.DiskFileName; the string you build is a proper path:

    c:\reports\BT-MOBILES.Doc  - Valid Path

    But when you create the string for your attachment, you are adding double quotes to the begining and end of the path; which makes the path syntax invalid:

    "c:\reports\BT-MOBILES.Doc"  -  Invaild Path!

    Does that make sense

    Also, there are a couple of methods that are very useful for managing files without user intervention:

    System.IO.Path.GetTempFileName()
     - Returns a string with a path to a uniquely named temp file initialized to 0 bytes.

    System.Environment.GetFolderPath(Environment.SpecialFolder)
    - Returns the path to the foldder chosen from the Environment.SpecialFolder enumeration (i.e. Desktop, My Documents, System, Temp, Etc.).

  • jecottrell65

    You're using the value of the DateTimePicker in creating your filename.  The Value contains invalid characters for filenames.  If you want to include a date component in your file name, use something like:

    a.Value.ToString.Replace("/", "-").Replace(":", "-")

    You want to make sure that there are no invalid characters in the file name string that you build.

  • Janus Sejr

    You'll need to be able to save the report to a file so that you can attach that file to your email.  Here are the basic steps to sending an email in .NET:


    'Create a SMTPMail Object
            Dim smtp As System.Web.Mail.SmtpMail

    'Create a new Mail Message Object
            Dim msg As New System.Web.Mail.MailMessage

    'Create a new attachment using the path to the file you saved
            Dim atch As New System.Web.Mail.MailAttachment("C:\Path To Saved File\Saved File.Name")

    'Set the SMTP Server address of the SMTPMail object, make sure it is a server your computer is allowed to send through
            smtp.SmtpServer = "smtp.server.address"

    'Add the attachment to the message
            msg.Attachments.Add(atch)

    'Set the From Address of the message
            msg.From = "me@mydomain.com"

    'Set the To Address of the message
            msg.To = "therecipient@mydomain.com"

    'Set the Subject of the message
            msg.Subject = "This is the subject of the email"

    'Set the Body of the message
            msg.Body = "This is the body of the email"

    'Note that there are additional Message properties you can set; the ones above are the most common and essential

    'Send the message
            smtp.Send(msg)


    And that's pretty much how mail works!

  • neosamz

    hi rikimble 
    again a lots of thanx i have tried the code to save and email a report and it is working 
    now.
    being a begineer i m much greatful to you that you have guided me so nicely i just want to know that in future i will definately need your help so how can i discuss you my problems 

    thanx

  • D. M. More

    thanx a lot dear rkimble i will try it today and let you know if i feel any difficulty 

    you are really a saint for the new starters like me 

    regards

    ali

  • event on scaning barcode