Function Azalea_Code_128_A(ByVal yourData As String) As String ' C128Tools 29may12 jwhiting ' Copyright 2012 Azalea Software, Inc. All rights reserved. www.azaleabarcodes.com ' Creating a Code 128 code set A barcode using C128Tools. ' Your input, yourData, is a string to be encoded as a Code 128 code set A symbol. ' yourData must be the Code 128 code set A character set. Input error checking is your responsibility. Dim temp As String ' a temporary placeholder Dim chunk As String ' loop chunk Dim i As Integer ' our loop counter Dim checkDigitSubtotal As Integer ' a check digit throwaway Dim e As Integer ' a placeholder variable ' seed the variables temp = Chr(181) ' code set A start glyph checkDigitSubtotal = 103 ' code set A start checkdigit value ' map the input string into the C128Tools character set For i = 1 To Len(yourData) Step 1 chunk = Mid(yourData, i, 1) Select Case Asc(chunk) ' map from above ASCII 182 placeholders to the font's character assignments Case Is > 95 temp = temp & Chr(Asc(chunk) - 66) Case Is = 32 ' move the space character temp = temp & Chr(206) Case Else temp = temp & chunk End Select Next i ' Calculate the Code 128 mod 103 check digit For i = 1 To Len(yourData) e = Asc(Mid(yourData, i, 1)) - 32 If e <> 142 Then checkDigitSubtotal = checkDigitSubtotal + (e * i) End If Next i checkDigitSubtotal = checkDigitSubtotal Mod 103 ' Put together the final output string ' code set A start bar, the encoded string, check digit, stop bar Select Case checkDigitSubtotal Case 0 Azalea_Code_128_A = temp & Chr(206) & Chr(196) Case 1 To 93 Azalea_Code_128_A = temp & Chr(checkDigitSubtotal + 32) & Chr(196) Case Is > 93 Azalea_Code_128_A = temp & Chr(checkDigitSubtotal + 103) & Chr(196) End Select End Function