I got the encoding routine for the 3 of 9 barcode years ago when a project I worked on needed barcodes and I will post it here since it was free when I got it. However I do not remember where I got it but a simple Google search should get you more encoding algorithms for other barcodes.
'This is a VB function that will return a string expression
'formatted for use with the 3 of 9 barcode font using a checkdigit
'To print the barcode on a report send the data to this function and
'print the return data using the 3of9.ttf TrueType Font
Function Barcode39(InString As String) As String
' This function returns the input string with:
' a start *, the original string, a check digit, and a stop *
Dim i As Integer ' Counter
Dim Chk As Integer ' Check Digit
Dim Char1 As String ' Current character
Dim c39CharSet As String ' The 3 of 9 43 character set
c39CharSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
Chk = 0
For i = 1 To Len(InString)
Char1 = Mid$(InString, i, 1)
' find the position of this character in the valid set of
' 43 characters and subtract 1 (zero based)
Chk = Chk + (InStr(c39CharSet, Char1) - 1)
Barcode39 = "*" + InString + Mid$(c39CharSet, (Chk Mod 43) + 1, 1) + "*"
With these two pieces you should be able to print 3 of 9 barcode in just about 2 minutes.
Hope this helps and if anybody has a solution for creating barcode from scratch I am all ears... ;)
Hi can u please let me know the way to use other types of fonts like Code93,because with this code i am able to print but my barcode is going out of the label width,n if i minimize the size then barcode is not scanning.Can you please let me know any alternate solution to avoid this problem.
hi, you said you needed a Visual Basic code for printing a barcode in a normal printer, I know a web about barcode printer, I think it is useful for you, you can check it to find that whether it is useful for you, hope you like it. best regards!
For Each ctrl As Control In Me.Controls("pnlMainPanel").Controls
If ctrl.GetType Is GetType(System.Windows.Forms.Panel) Then
For Each subCtrl As Control In ctrl.Controls
If subCtrl.GetType Is GetType(System.Windows.Forms.TextBox) Then
If subCtrl.GetType Is ...