Function Azalea_Code_128_B(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 B barcode using C128Tools. ' Your input, yourData, is a string to be encoded as a Code 128 code set B symbol. ' yourData must be the Code 128 code set B 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(182) ' code set B start glyph checkDigitSubtotal = 104 ' code set B 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 200 to the actual character assignments Case Is > 200 temp = temp & Chr(Asc(chunk) - 35) ' The space character is at ASCII 194 because TrueType ' doesn't allow a glyph in the ASCII 32 slot Case Is = 32 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_B = temp & Chr(206) & Chr(196) Case 1 To 93 Azalea_Code_128_B = temp & Chr(checkDigitSubtotal + 32) & Chr(196) Case Is > 93 Azalea_Code_128_B = temp & Chr(checkDigitSubtotal + 103) & Chr(196) End Select End Function