I downloaded the Epicor Code128.ttf font to my local c:\windows\fonts - however, to create the barcode requires encoding.
Does anyone have a sample code for SSRS (VB Code) for Encoding?
I tried to download the sample VB6 code from the font originator into the SSRS Code section however it causes Epicor SSRS Form (Job Traveler in this case) to fail. No specific error message so VERY difficult to debug.
We recently started looking into creating Code 128 labels and this is the code that we have been testing with…
When editing the SSRS document, click on the grey area and then the ‘code’ section will pop up in the top right. Paste the code underneath what is already there.
' Grandzebu CODE128.TTF encoder (ported to SSRS VB.NET)
' Returns an encoded string that must be rendered with Font = "Code 128"
Public Function Code128(ByVal input As Object) As String
If input Is Nothing Then Return ""
Dim chaine As String = CStr(input)
If chaine.Length = 0 Then Return ""
' Validate characters: ASCII 32..126 plus 203 (used by this font for special function)
For i As Integer = 0 To chaine.Length - 1
Dim a As Integer = AscW(chaine.Substring(i, 1))
If Not ((a >= 32 AndAlso a <= 126) OrElse a = 203) Then
Return ""
End If
Next
Dim code As String = ""
Dim tableB As Boolean = True
Dim iPos As Integer = 0
While iPos < chaine.Length
If tableB Then
' Decide if it is worth switching to Table C
' yes for 4 digits at start or end, else for 6 digits
Dim mini As Integer = If(iPos = 0 OrElse iPos + 3 = chaine.Length - 1, 4, 6)
If HasAtLeastNDigits(chaine, iPos, mini) Then
' Switch/Start in table C
If iPos = 0 Then
code = ChrW(210) ' Start C
Else
code &= ChrW(204) ' Code C switch
End If
tableB = False
Else
If iPos = 0 Then
code = ChrW(209) ' Start B
End If
End If
End If
If Not tableB Then
' We are in table C: try to encode 2 digits
If HasAtLeastNDigits(chaine, iPos, 2) Then
Dim pairVal As Integer = Integer.Parse(chaine.Substring(iPos, 2))
Dim dummy As Integer = If(pairVal < 95, pairVal + 32, pairVal + 105)
code &= ChrW(dummy)
iPos += 2
Else
' Not 2 digits -> switch back to table B
code &= ChrW(205) ' Code B switch
tableB = True
End If
End If
If tableB Then
' Encode 1 character in table B
code &= chaine.Substring(iPos, 1)
iPos += 1
End If
End While
' Checksum calculation
Dim checksum As Integer = 0
For i As Integer = 0 To code.Length - 1
Dim dummy As Integer = AscW(code.Substring(i, 1))
dummy = If(dummy < 127, dummy - 32, dummy - 105)
If i = 0 Then
checksum = dummy
End If
checksum = (checksum + i * dummy) Mod 103
Next
Dim checkChar As Integer = If(checksum < 95, checksum + 32, checksum + 105)
' Add checksum + STOP
code &= ChrW(checkChar) & ChrW(211) ' Stop
Return code
End Function
Private Function HasAtLeastNDigits(ByVal s As String, ByVal startIndex As Integer, ByVal n As Integer) As Boolean
If startIndex + n > s.Length Then Return False
For j As Integer = 0 To n - 1
Dim ch As Char = s.Chars(startIndex + j)
If ch < "0"c OrElse ch > "9"c Then Return False
Next
Return True
End Function
EpicCare sent this over when I opened a ticket about it recently: