This site will look much better in a browser that supports web standards, but it is accessible to any browser or Internet device.
The following functions can be used within Microsoft Visual Basic to create and print UPC barcodes using Azalea Software's barcode fonts. Other functions are available for Bookland, Code 128, Code 39, and Interleaved 2 of 5.
These functions can be ported to other languages and development tools. Copy, paste, and edit the code as needed. Our copyright notice must remain intact. When you port, please send us a copy so we can learn something new. AtDhVaAnNkCsE
This sample code is provided as is. While every attempt has been made to insure that it works correctly, please double-check it against the results obtained from our bundled wizard utility. Please report any bugs or problems.
Function Azalea_UPC_A(ByVal UPCnumber As String) As String
' UPCTools 30aug07 gacadogan
' Copyright 2007 Azalea Software, Inc. All rights reserved. www.azalea.com
' The input, UPCnumber, is a string to be converted into a UPC version A barcode.
Dim checkDigitSubtotal As Integer ' check digit throwaway
Dim i As Integer ' loop counter
Dim checkDigit As String ' check digit itself
Dim temp As String ' placeholder variable
' Valid input is 11-digits (no check digit), 12-digits (with check digit), or 14-digits (GTIN).
Select Case Len(UPCnumber)
Case 11
' do check digit calculation
Case 12
' ignore their check digit & use ours (TBD compare and handle mismatches)
UPCnumber = Left(UPCnumber, 11)
Case 14
' GTIN input, strip leading 2 characters & last one too;
UPCnumber = Mid(UPCnumber, 3, 11)
Case Else
8' error handling goes here
End Select
' string substitution for the 1st character in lower-right corner
Select Case Left(UPCnumber, 1)
Case "0"
temp = "U|xa"
Case "1"
temp = "[|xb"
Case "2"
temp = "V|xc"
Case "3"
temp = "W|xd"
Case "4"
temp = "X|xe"
Case "5"
temp = "Y|xf"
Case "6"
temp = "Z|xg"
Case "7"
temp = "u|xh"
Case "8"
temp = "\|xi"
Case "9"
temp = "]|xj"
End Select
' string substitution for left notch
For i = 2 To 6 Step 1
temp = temp + Chr(65 + (Val(Mid(UPCnumber, i, 1))))
Next i
' do the check digit
checkDigitSubtotal = (Val(Left(UPCnumber, 1))) + (Val(Mid(UPCnumber, 3, 1))) + (Val(Mid(UPCnumber, 5, 1))) + (Val(Mid(UPCnumber, 7, 1))) + (Val(Mid(UPCnumber, 9, 1))) + (Val(Right(UPCnumber, 1)))
checkDigitSubtotal = (3 * checkDigitSubtotal) + (Val(Mid(UPCnumber, 2, 1))) + (Val(Mid(UPCnumber, 4, 1))) + (Val(Mid(UPCnumber, 6, 1))) + (Val(Mid(UPCnumber, 8, 1))) + (Val(Mid(UPCnumber, 10, 1)))
checkDigit = Right(Str(300 - checkDigitSubtotal), 1)
' add the center guard bar, product number, check digit & right guard bar
temp = temp + "y" + Right(UPCnumber, 5) + Chr(107 + (Val(checkDigit))) + "z"
' the check digit human readable
Select Case checkDigit
Case "0"
Azalea_UPC_A = temp + "U"
Case "1"
Azalea_UPC_A = temp + "["
Case "2"
Azalea_UPC_A = temp + "V"
Case "3"
Azalea_UPC_A = temp + "W"
Case "4"
Azalea_UPC_A = temp + "X"
Case "5"
Azalea_UPC_A = temp + "Y"
Case "6"
Azalea_UPC_A = temp + "Z"
Case "7"
Azalea_UPC_A = temp + "u"
Case "8"
Azalea_UPC_A = temp + "\"
Case "9"
Azalea_UPC_A = temp + "]"
End Select
' Format the output, Azalea_UPC_A, in one of Azalea Software's UPC fonts.
' For example in Excel, B1=Azalea_UPC_A(A1)
' Or put another way, yourContainer.text=Azalea_UPC_A(yourInputString)
End Function