title: Crystal Reports Code 128 Barcode Printing Shape Instead of Number
body: <p>I have a formula field with a font of Code 128, to print string input from a user.</p>
  
  <p>It prints fine every time except when two (2) zeros are next to each other. But the thing is its fine when it prints 100, but say I do 1000, it prints some rectangle shape in the barcode. Again 1001 it prints fine, 10001 it prints with a rectangle.</p>
  
  <p>Here is the formula field:</p>
  
  <p><strong>@QuantityBarCode</strong></p>
  
  <pre><code>' http://support.wisys.com/documentation/Crystal_Report_IDAutomation_Basic_Syntax_Barcode_Settings.htm
  
  Dim DataToEncode As String
  DataToEncode = Trim({@Quantity}) ' Quantity
  Dim PrintableString As String
  Dim DataToFormat 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
  Dim CurrentEncoding As String
  Dim C128Start As String
  Dim CorrectFNC As Number
  Dim CurrentChar As String
  CorrectFNC = 0
  PrintableString = ""
  DataToFormat = DataToEncode
  DataToEncode = ""
  
  'Here we select character set A, B or C for the START character
  StringLength = Len(DataToFormat)
  CurrentCharNum = Asc(Mid(DataToFormat, 1, 1))
  If CurrentCharNum &lt; 32 Then C128Start = Chr(203)
  If CurrentCharNum &gt; 31 And CurrentCharNum &lt; 127 Then C128Start = Chr(204)
  If ((StringLength &gt; 4) And IsNumeric(Mid(DataToFormat, 1, 4))) Then C128Start = Chr(205)
  
  '202 &amp; 212-215 is for the FNC1, with this Start C is mandatory
  If CurrentCharNum = 202 Then C128Start = Chr(205)
  If CurrentCharNum = 212 Then C128Start = Chr(205)
  If CurrentCharNum = 213 Then C128Start = Chr(205)
  If CurrentCharNum = 214 Then C128Start = Chr(205)
  If CurrentCharNum = 215 Then C128Start = Chr(205)
  If C128Start = Chr(203) Then CurrentEncoding = "A"
  If C128Start = Chr(204) Then CurrentEncoding = "B"
  If C128Start = Chr(205) Then CurrentEncoding = "C"
  
  For I = 1 To StringLength
      'check for FNC1 in any set which is ASCII 202 and ASCII 212-215
      CurrentCharNum = Asc(Mid(DataToFormat, I, 1))
  If ((CurrentCharNum = 202) Or (CurrentCharNum = 212) Or (CurrentCharNum = 213) Or (CurrentCharNum = 214) Or (CurrentCharNum = 215)) Then
          DataToEncode = DataToEncode &amp; Chr(202)
      'check for switching to character set C
  ElseIf ((I &lt; StringLength - 2) And (IsNumeric(Mid(DataToFormat, I, 1))) And (IsNumeric(Mid(DataToFormat, I + 1, 1))) And (IsNumeric(Mid(DataToFormat, I, 4)))) Or ((I &lt; StringLength) And (IsNumeric(Mid(DataToFormat, I, 1))) And (IsNumeric(Mid(DataToFormat, I + 1, 1))) And (CurrentEncoding = "C")) Then
      'switch to set C if not already in it
          If CurrentEncoding &lt;&gt; "C" Then DataToEncode = DataToEncode &amp; Chr(199)
          CurrentEncoding = "C"
          CurrentChar = Mid(DataToFormat, I, 2)
          CurrentValue = Val(CurrentChar)
      'set the CurrentValue to the number of String CurrentChar
  If (CurrentValue &lt; 95 And CurrentValue &gt; 0) Then DataToEncode = DataToEncode &amp;                                                                                          Chr(CurrentValue + 32)
          If CurrentValue &gt; 94 Then DataToEncode = DataToEncode &amp; Chr(CurrentValue + 100)
          If CurrentValue = 0 Then DataToEncode = DataToEncode &amp; Chr(194)
          I = I + 1
      'check for switching to character set A
  ElseIf (I &lt;= StringLength) And ((Asc(Mid(DataToFormat, I, 1)) &lt; 31) Or  ((CurrentEncoding = "A") And (Asc(Mid(DataToFormat, I, 1)) &gt; 32 And (Asc(Mid(DataToFormat, I, 1))) &lt; 96))) Then
      'switch to set A if not already in it
          If CurrentEncoding &lt;&gt; "A" Then DataToEncode = DataToEncode &amp; Chr(201)
          CurrentEncoding = "A"
      'Get the ASCII value of the next character
          CurrentCharNum = Asc(Mid(DataToFormat, I, 1))
          If CurrentCharNum = 32 Then
              DataToEncode = DataToEncode &amp; Chr(194)
          ElseIf CurrentCharNum &lt; 32 Then
              DataToEncode = DataToEncode &amp; Chr(CurrentCharNum + 96)
          ElseIf CurrentCharNum &gt; 32 Then
              DataToEncode = DataToEncode &amp; Chr(CurrentCharNum)
          End If
      'check for switching to character set B
   ElseIf (I &lt;= StringLength) And (((Asc(Mid(DataToFormat, I, 1))) &gt; 31) And ((Asc(Mid(DataToFormat, I, 1)))) &lt; 127) Then
      'switch to set B if not already in it
          If CurrentEncoding &lt;&gt; "B" Then DataToEncode = DataToEncode &amp; Chr(200)
          CurrentEncoding = "B"
      'Get the ASCII value of the next character
          CurrentCharNum = Asc(Mid(DataToFormat, I, 1))
          If CurrentCharNum = 32 Then
              DataToEncode = DataToEncode &amp; Chr(194)
          Else
              DataToEncode = DataToEncode &amp; Chr(CurrentCharNum)
          End If
      End If
  Next I
  
  '&lt;&lt;&lt;&lt; Calculate Modulo 103 Check Digit &gt;&gt;&gt;&gt;
  WeightedTotal = Asc(C128Start) - 100
  StringLength = Len(DataToEncode)
  For I = 1 To StringLength
      CurrentCharNum = Asc(Mid(DataToEncode, I, 1))
      If CurrentCharNum &lt; 135 Then CurrentValue = CurrentCharNum - 32
      If CurrentCharNum &gt; 134 Then CurrentValue = CurrentCharNum - 100
      If CurrentCharNum = 194 Then CurrentValue = 0
      CurrentValue = CurrentValue * I
      WeightedTotal = WeightedTotal + CurrentValue
      If CurrentCharNum = 32 Then CurrentCharNum = 194
      PrintableString = PrintableString &amp; Chr(CurrentCharNum)
  Next I
  CheckDigitValue = (WeightedTotal Mod 103)
  If CheckDigitValue &lt; 95 And CheckDigitValue &gt; 0 Then C128CheckDigit = Chr(CheckDigitValue + 32)
  If CheckDigitValue &gt; 94 Then C128CheckDigit = Chr(CheckDigitValue + 100)
  If CheckDigitValue = 0 Then C128CheckDigit = Chr(194)
  DataToEncode = ""
  
  ' Final Barcode format
  Formula = C128Start &amp; PrintableString &amp; C128CheckDigit &amp; Chr(206) &amp; " "
  </code></pre>
  
  <p>The image shows 1000 as text (user input) and the barcode prints with the rectangle and I also added the barcode text to the bottom right corner to show what the barcode text looks like when encoded. I have noticed that the asterisk seems to be in the text when I get this weird shape.</p>
  
  <p>Any help would be greatly appreciated :)</p>
  
  <p><img src="https://i.stack.imgur.com/nCqm4.jpg" alt="enter image description here"></p>