'*********************************************************************
'*  IDAutomation Barcode Font Formulas for Crystal Reports 4.01
'*  Copyright, IDAutomation.com, Inc. 2000-2004. All rights reserved.
'*
'*  You MUST use the fully functional Code 128 (dated 12/2000 or later)
'*  font for this code to create and print a proper barcode
'*
'*  You may incorporate our Source Code in your application
'*  only if you own a valid License from IDAutomation.com, Inc.
'*  for the associated font and the copyright notices are not
'*  removed from the source code.
'*
'*  Formula: Code128b - formats output to IDAutomationC128 fonts
'*  Tutorial: http://www.BizFonts.com/crystal/
'*********************************************************************
Dim DataToEncode As String
'Change the next line to connect to your data source; for example:
'DataToEncode = ({Table.Field})
DataToEncode = "123456789012"
Dim PrintableString As String
Dim WeightedTotal As Number
Dim CurrentValue As Number
Dim CheckDigitValue As Number
Dim C128CheckDigit As String
Dim StringLength As Number
Dim I As Number
Dim CurrentCharNum As Number
PrintableString = ""
WeightedTotal = 104
PrintableString = Chr(204)
StringLength = Len(DataToEncode)
For I = 1 To StringLength
    CurrentCharNum = Asc(Mid(DataToEncode, I, 1))
    If CurrentCharNum < 135 Then CurrentValue = CurrentCharNum - 32
    If CurrentCharNum > 134 Then CurrentValue = CurrentCharNum - 100
    CurrentValue = CurrentValue * I
    WeightedTotal = WeightedTotal + CurrentValue
    If CurrentCharNum = 32 Then CurrentCharNum = 194
    PrintableString = PrintableString & Chr(CurrentCharNum)
Next I
CheckDigitValue = (WeightedTotal Mod 103)
If CheckDigitValue < 95 And CheckDigitValue > 0 Then C128CheckDigit = Chr(CheckDigitValue + 32)
If CheckDigitValue > 94 Then C128CheckDigit = Chr(CheckDigitValue + 100)
If CheckDigitValue = 0 Then C128CheckDigit = Chr(194)
PrintableString = PrintableString & C128CheckDigit & Chr(206) & " "
Formula = PrintableString
