Printing Code 93 Bar Codes in Visual Basic

The following functions can be used within Microsoft Visual Basic to create and print Code 93 barcodes using Azalea Software's barcode fonts. Other functions are available for UPC, ISBN-13, Code 39 (far more common than Code 93!), Interleaved 2 of 5, and Code 128.

Our Code 93 Visual Basic function can be ported to other languages and development tools. You may copy, paste, and edit the code as you wish, but please remember that our copyright notice must remain intact. If you port it, please send us a copy so we can learn something new. AtDhVaAnNkCsE

This sample code is provided as is and input error correction is your responsibility. Please report any bugs or problems. As always, if you have any questions or are curious about specs, check out the product's documentation or drop us an email at technicalsupport at azalea dot com.

Function AzaleaCode93CheckDigits(ByVal C93 As String) As String
' C93Tools v6.0 Copyright 2008 Jerry Whiting. All rights reserved.
' Azalea Software, Inc. www.azalea.com

' The input, C93, is a string consisting of the 47-character version
' of Code 93 with the start and stop bars (*).
' The output, AzaleaCode93CheckDigits, is the input string, the C and K mod 47
' check digits, and the start and stop bars.

Dim charSet As String ' mod 47 lookup table
Dim i As Integer ' loop counter
Dim Rev As String ' reverser
Dim indice() As Byte ' indicator
Dim check1 ' first check digit (C)
Dim check2 ' second check digit (K)

charSet = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ-. $/+%abcd"

' This reverses the input
For i = Len(C93) To 1 Step -1
Rev = Rev & Mid(C93, i, 1)
Next

' This reserves a place for the first check digit which
' will be part of the array for the second check digit calculation
ReDim indice(1 To Len(C93) + 1)

' We give an indice between 0-46 to every element of the Rev array
' Each indice corresponds to the position of each element of the Rev string in charSet
For i = 1 To Len(Rev)
indice(i + 1) = InStr(1, charSet, Mid(Rev, i, 1)) - 1
Next

' This creates the first check digit, C check digit
For i = 2 To Len(Rev) + 1
check1 = check1 + ((i - 1) Mod 20) * indice(i)
Next i

' C check digit
check1 = check1 Mod 47
indice(1) = check1

' This creates the second check digit, K check digit
For i = 1 To Len(Rev) + 1
check2 = check2 + (i Mod 15) * indice(i)
Next i

' K check digit
check2 = check2 Mod 47

' Build the output string: start bar, input string, C and K check digits and stop bar
AzaleaCode93CheckDigits = "<" & C93 & Mid(charSet, check1 + 1, 1) & Mid(charSet, check2 + 1, 1) & ">"

End Function