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
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)