Search code examples
c#crystal-reports

how to add start and end point for my barcode report?


I created barcode crystal report for customers attendance , I used the font IDAutomationHC39M and created stored procedure to generate the barcode

then I created the following void and print the label report when click the button

private void btnbarcode_Click(object sender, EventArgs e)
        {
                   
                RPT.barcode myreport = new RPT.barcode();
                myreport.SetParameterValue("@INVOICE_ID", txtOrder.Text);
                myreport.SetDatabaseLogon("admin", "1234");
                RPT.RPT_TESTS myform = new RPT.RPT_TESTS();
                myform.crystalReportViewer1.ReportSource = myreport;
                myform.ShowDialog();
            
        }

the issue barcode reader not reading the barcode after I print the labels , I read some posts that I need to add start point and end point like this

"*" invoice_ID "*" 

how I will solve this issue and fix the barcode to be readable from barcode reader how to add start and end point to my code and is this the correct font IDAutomationHC39 ?


Solution

  • You can manually encode this barcode using a formula such as "*" & invoice_ID & "*". The formula you shared had all the right elements to work, you just needed the ampersands to signal the text values should be concatenated. You may need to use the ToText() function to cast your invoice number as a text data type to avoid errors if your invoice numbers are entirely numeric. So that would change the formula to "*" & ToText(invoice_ID) & "*".

    However, I highly recommend looking into getting a User Function Library, aka UFL, that contains a function for encoding a Code 39 barcode. The manual encoding you are using can lead to some issues because there is more to the encoding than just a start and stop code, such as testing for illegal characters in the string. The functions in a good UFL will test the value being encoded to ensure there are no illegal characters in a dynamic fashion that can be reused over and over quickly and easily without having to rewrite code for the encoding process directly into a formula. This isn't as big of an issue with Code 39 barcodes due to their simplistic nature, but its still useful to avoid having to memorize the allowed characters, especially if you ever need to work with other barcode types that have checksum digits. Calculating those checksum values on your own can be painful.

    I use the Azalea UFL found here. But there are a lot of other UFLs available from different sources that are easily found with a Google search.

    Once you have the DLL file dropped into the correct folder for your version of Crystal Reports, its as easy as creating a Formula Field that calls the function to encode a Code 39 barcode. Then all you have to do is place the formula field on your report and set the font to an appropriate barcode font.