Option Explicit Function Azalea_Code_128_A(ByVal yourData As String) As String ' C128Tools v6.0 24apr07 rev 001 jwhiting ' Copyright 2007 Azalea Software, Inc. All rights reserved. www.azalea.com ' yourData is a string to be encoded as a Code 128 code set A symbol. ' yourData must be an uppercase letters only. Input error checking is your responsibility. ' Format the output, Azalea_Code_128_A, using one of Azalea Software's Code 128 barcode fonts. Dim fontString As String ' encoded data Dim chunk As String ' loop variable Dim i As Integer ' just a counter Dim checkDigitSubtotal As Integer ' weighted subtotal Dim e As Integer ' placeholder variable ' seed the variables fontString = Chr(181) ' code set A start glyph checkDigitSubtotal = 103 ' code set A start checkdigit value ' map the input string into the Azalea Code 128 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 fontString = fontString & Chr(Asc(chunk) - 66) Case Is = 32 ' move the space character fontString = fontString & Chr(206) Case Else fontString = fontString & chunk End Select Next i ' the mod 103 check digit calculation 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 ' build the output string ' code set A start bar, the encoded string, check digit, stop bar Select Case checkDigitSubtotal Case 0 Azalea_Code_128_A = fontString & Chr(194) & Chr(196) Case 1 To 93 Azalea_Code_128_A = fontString & Chr(checkDigitSubtotal + 32) & Chr(196) Case Is > 93 Azalea_Code_128_A = fontString & Chr(checkDigitSubtotal + 103) & Chr(196) End Select End Function