Printing Interleaved 2 of 5 Bar Codes in Visual Basic

Azalea Software’s barcode fonts come with the functions you’ll need within Microsoft Visual Basic to create and print Interleaved 2 of 5 barcodes using our barcode fonts. Other Visual Basic functions are available for UPC, Code 39, Interleaved 2 of 5, and POSTNET.

You may port these functions to other languages and development tools, so feel free to copy, paste, and edit the code as needed; our sole caveat is that our copyright notice must remain intact. When you port, or if you find a bug or something that needs improvement, please send us a copy so we can learn something new. (Our email address is technicalsupport at azalea dot com…and as always, AtDhVaAnNkCsE!)

Our Visual Basic sample code is provided as is. While every attempt has been made to ensure that it works correctly, please double-check it against the results obtained from our bundled wizard utility that comes with I2of5Tools.

Module I2of5
Function AzaleaI2of5(ByVal I2of5number As String) As String
  ' I2of5Tools v6.0 Copyright 2008 Azalea Software, Inc. All rights reserved. www.azalea.com
  ' The input, I2of5number, is a numbers-only string.
  ' Format the output, AzaleaI2of5, using Azalea's Interleaved 2 of 5 fonts.
  Dim i As Integer
  Dim temp As String
  Dim temp2 As String  ' placeholder
  Dim chunk As String  ' placeholder
  If Len(I2of5number) Mod 2 <> 0 Then  ' if the input has odd number of digits
    I2of5number = "0" + I2of5number    ' pad it with a leading zero
  End If
  temp2 = I2of5number  ' divide input into pairs of digits
  For i = 1 To Len(I2of5number) / 2
    chunk = Left(temp2, 2)     ' grab 2 characters
    If Val(chunk) < 90 Then    ' offset into fonts' character set
      temp = temp + Chr(Val(chunk) + 33)
    ElseIf Val(chunk) = 90 Then
       temp = temp + Chr(182)
    ElseIf Val(chunk) = 91 Then
       temp = temp + Chr(183)
    ElseIf Val(chunk) > 91 Then
       temp = temp + Chr(Val(chunk) + 104)
    End If
    temp2 = Right(temp2, Len(temp2) - 2)  ' move to the next two characters
  Next i
  ' add the start and stop bars (ASCII 171 & ASCII 172)
  AzaleaI2of5 = Chr(171) + temp + Chr(172)
  ' Format the output, AzaleaI2of5, using Azalea Software's Interleaved 2 of 5 font.
  ' yourContainer.text = AzaleaI2of5(yourString)
End Function
End Module