Click here to Skip to main content
15,887,946 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
Dim Code128Digits As String = " !""#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"


    ' This function generates a barcode based on the text, symbology
    ' and check digit settings you provide
    Function GenerateBarcode(ByVal Text As String, _
                           ByVal CheckDigit As Boolean) As String
        ' Return string
        Dim s As String = ""
        ' Individual character from input
        Dim c As String = ""
        ' Sum of all the values of the characters to generate check digit
        Dim v As Integer = 0
        ' Error flag
        Dim err As Boolean = False
        ' Generate barcode based on symbology
        ' Loop through each input character

        For i As Integer = 0 To Text.Length - 1
            c = Text.Substring(i, 1)
            ' Is it a valid digit?
            Dim j As Integer = Code128Digits.IndexOf(c)
            If (j > -1) Then
                ' We'll add to our check digit calculation
                v = v + (j * (i + 1))
                s = s & c
            Else
                err = True
            End If
        Next
        ' Add Start Symbol
        s = Chr(196) & s
        v = v + 103


        ' Add the check digit if one was requested

        If (CheckDigit) Then
            v = v Mod 103
            If (v <= 94) Then
                s = s & Code128Digits.Substring(v, 1)
            Else
                ' If check digit value is greater than 94, we need to add
                ' special characters
                Dim t As String = Chr(195) + Chr(201) + Chr(202) + Chr(200) + Chr(203) + Chr(204) + Chr(205) + Chr(206)
                s = s & t.Substring(v - 95, 1)
            End If
        End If
        ' Add a Stop Symbol
        s = s.Replace(" ", Chr(207)) & Chr(199)
        If err = True Then
            s = ""
        End If
        ' Return the resultant string
        Return s
    End Function


I am using This Function,
barcode scanner reading 6 Character ,eg: i input "wcf004"
barcode scanner cannot reading 10 Character, eg: I input "fnc0000580"

Please Help me
Posted
Updated 14-May-12 18:26pm
v2
Comments
Dave Kreskowiak 15-May-12 0:45am    
Sooooo your generating a barcode, but the barcode you generate, if 10 characters long, cannot be read by a barcode scanner??

Why do I get the feeling that you just picked up this code from somewhere and have no idea how it works or why?

Perhaps you're getting your calculating the checkdigit incorrectly?? You may want to read through http://en.wikipedia.org/wiki/Code_128
Sandeep Mewara 15-May-12 2:05am    
And did you debugged and followed what the implementation is? How the execution is going on? Where the change is needeD?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900