This site will look much better in a browser that supports web standards, but it is accessible to any browser or Internet device.

bar code software

Azalea Software, Inc.


Printing Code 39 Bar Codes in Visual Basic

The following functions can be used within Microsoft Visual Basic to create and print Code 39 barcodes using Azalea Software's barcode fonts. Other functions are available for UPC, Code 128, Interleaved 2 of 5, and POSTNET.

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 AzaleaCode39(ByVal C39 as String) as String
' C39Tools v5.0 09.10.00 jwhiting
' Copyright 2000 Azalea Software, Inc. All rights reserved. www.azalea.com
  ' The input, C39, is a string consisting of the 44-character version
  ' of Code 39 without the start and stop bars (*).
  ' Format the output, AzaleaCode39, using Azalea's Code 39 fonts.
  Dim i As Integer    ' loop counter
  Dim chunk As String ' loop variable
  Dim temp As String  ' temp variable
  ' Because TrueType doesn't support glyphs in the space slot (ASCII 32)
  ' we've moved the space character to the underscore ( _ ).
  ' Here's the search and replace.
  For i = 1 To Len(C39)
    chunk$ = Mid$(C39, i, 1)
    If chunk = " " Then
      temp = temp + "_"
    Else
      temp = temp + chunk
    End If
  Next i
  ' put together the final string with the start and stop bars
  AzaleaCode39 = "*" + temp + "*"
  ' Format the output, AzaleaCode39, using Azalea Software's Code 39 font.
  ' yourContainer.text = AzaleaCode39(yourString)
End Function

Function AzaleaCode39ASCII(ByVal C39 as String) as String
' C39Tools v5.0 09.10.00 jwhiting
' Copyright 2000 Azalea Software, Inc. All rights reserved. www.azalea.com
  ' The input, C39, gets mapped into the Full ASCII version of Code 39.
  ' Format the output, AzaleaCode39, using Azalea's Code 39 fonts.
  Dim i As Integer    ' loop counter
  Dim chunk As String ' loop variable
  Dim temp As String  ' temp variable
' map into the Full ASCII version of Code 39
  For i = 1 To Len(C39)
    chunk = Mid(C39, i, 1)
    Select Case Asc(chunk)
      Case 0
        temp = temp + "%U"
      Case 1 To 26
        temp = temp + "$" + Chr(Asc(chunk) + 64)
      Case 27 To 31
        temp = temp + "%" + Chr(Asc(chunk) + 38)
      Case 32
      ' Because TrueType doesn't support glyphs in the space slot (ASCII 32)
      ' we've moved the space character to the underscore ( _ ).
      ' Here's the search and replace.
        temp = temp + "_"
      Case 33 To 44
        temp = temp + "/" + Chr(Asc(chunk) + 32)
      Case 45 To 46
        temp = temp + chunk
      Case 47
        temp = temp + "/O"
      Case 48 To 57
        temp = temp + chunk
      Case 58
        temp = temp + "/Z"
      Case 59 To 63
        temp = temp + "%" + Chr(Asc(chunk) + 11)
      Case 64
        temp = temp + "%V"
      Case 65 To 90
        temp = temp + chunk
      Case 91 To 95
        temp = temp + "%" + Chr(Asc(chunk) - 16)
      Case 96
        temp = temp + "%W"
      Case 97 To 122
        temp = temp + "+" + Chr(Asc(chunk) - 32)
      Case 123 To 126
        temp = temp + "%" + Chr(Asc(chunk) - 43)
      Case 127
        temp = temp + "%T"
    End Select
  Next i
  ' put together the final string with the start and stop bars
  AzaleaCode39ASCII = "*" + temp + "*"
  ' yourContainer.text = AzaleaCode39(yourString)
End Function

Code 39 is sometimes, though rarely, used with an optional mod 43 check digit.
Function AzaleaCode39checkDigit (ByVal C39 as String) as String
' C39Tools v5.0 09.10.00 jwhiting
' Copyright 2000 Azalea Software, Inc. All rights reserved. www.azalea.com
  ' The input, C39, is a string consisting of the 44-character version
  ' of Code 39 whithout the start and stop bars (*).
  ' The output, AzaleaCode39checkDigit, is the input string, the mod 43
  ' check digit and the start and stop bars.
  Dim charSet As String    ' mod 43 lookup table
  Dim i As Integer      ' loop counter
  Dim subtotal As Integer ' check digit subtotal
  charSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%"
  For i = 1 To Len(C39)
    subtotal = InStr(charSet, Mid(C39, i, 1)) - 1 + subtotal
  Next i
  ' concatenate the original string, C39, and the check digit character
  AzaleaCode39checkDigit = C39$ & Mid$(charSet, (subtotal Mod 43 + 1), 1)
End Function


contact ustechnical supportabout usour blogsite mapmisc.links