Function Azalea_GS1_128_B(ByVal yourData As String) As String ' C128Tools 31may12 jwhiting ' Copyright 2012 Azalea Software, Inc. All rights reserved. www.azaleabarcodes.com ' Create a GS1-128 code set B barcode in Excel ' 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) & Chr(205) ' code set B start & FNC1 checkDigitSubtotal = 206 ' code set B start (104) + FNC1 (102) checkdigit values ' 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) 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 + 1)) End If Next i checkDigitSubtotal = checkDigitSubtotal Mod 103 ' Put together the final output string ' code set B start bar, FNC1, inputString, check digit, stop bar Select Case checkDigitSubtotal Case 0 ' Mark Presley bug fix 19jan09 Azalea_GS1_128_B = temp & Chr(206) & Chr(196) Case 1 To 93 Azalea_GS1_128_B = temp & Chr(checkDigitSubtotal + 32) & Chr(196) Case Is > 93 Azalea_GS1_128_B = temp & Chr(checkDigitSubtotal + 103) & Chr(196) End Select End Function