Code 128
25 comentarios
I like the idea of the barcode fonts, they print ok, but the barcode reader cannot decipher them, Am I doing something wrong?
Grand Zebu, you rock!!!
You just saved my life man. If there's a way to donate some money, please let me know.
Thanks a lot dude
The Code 128 symbology has particular start and stop characters and a check sum. Look on Wikipedia or Google for Code 128 to find the "rules".
Hi nibblesmx,
I want to print bar code - Code128 font with the following data.
123 ABC
the data contains space in between and code 128 does not support. can anybody help me?
Thanks.
Pushkar
Hi. I used these fonts but barcode are not identified by the barcode reader. As "rjskoko" said must include the start and stop characters. In wikipedia say that start character in code 128 C is the ascii code 210 but how can I type it? Also as I see there isn't barcode for this ascii in the fonts!
They do not work. The stop character Î (ASCII 206) is not the same as it appears to this web page!!!
I've implemented this font to print voucher codes, I choose Code 128 B but when the result of the checksum is a character for example 127, it prints a white square. This is part of the code that I wrote. This code works for me, most of times.
Private Sub onPrint(ByVal sender As Object, ByVal ev As PrintPageEventArgs)
Dim printFont As New Font("code 128", 40)
Dim stringToBarCode As String = "251250000156"
Dim intChar As Integer
Dim stringBuild As New StringBuilder
Dim checksum As Integer = 104
Dim i As Integer = 1
Dim crcResult As Integer
stringBuild.Append(ChrW(204))
For Each c As Char In stringToBarCode.ToCharArray
intChar = Encoding.ASCII.GetBytes(c)(0)
If intChar >= 32 And intChar <= 126 Then
checksum += (intChar - 32) * i
i += 1
stringBuild.Append(c)
End If
Next
If checksum > 104 Then
crcResult = (checksum Mod 103) + 32
stringBuild.Append(ChrW(crcResult))
stringBuild.Append(ChrW(206))
ev.Graphics.DrawString(stringBuild.ToString, printFont, Brushes.Black, 1, 1)
End If
End Sub
How can it be solved?, Do I need to edit the font? if so, how can i do it?
this has no characters for start, and stop codes.
Start A is ascii 208, start B is ascii 209 and start c ascii 210. The stop code is allways 211. All these characters are not available with this font...
Help me please, i printed card with id but don´t put start, stop codes or digi controller, and then the reader can´t read my codebar, exist a solution ?
Help me please, i printed card with id but don´t put start, stop codes or digi controller, and then the reader can´t read my codebar, exist a solution ?
Thanks to David Aguilar and the info on Wikipedia I fixed the code to use this font. (Below the c# code)
public string Code128(string toEncode)
{
StringBuilder Encoded = new StringBuilder();
//Start code
Encoded.Append((char)204);
int sum = 104;
for (int i = 0; i < toEncode.Length; i++)
{
sum += ((char)toEncode[i] - 32) * (i+1);
Encoded.Append(toEncode[i]);
}
sum = sum % 103;
sum += 32;
//Checksum between 94 and 103 are encoded in the 200 - 206 range
if (sum > 94 && sum < 103)
sum += 105;
//Checksum
Encoded.Append((char)sum);
//Stop code
Encoded.Append((char)206);
return Encoded.ToString();
}
The Difference with the code of David is that if the checksum values is in the 95-102 we have the correct font on ASCII (200-207). I made several test and it works.
Hello, CirasaEric. Thanks for the code. Could you please give us instructions on how to use this code. When I try to use putting it in a macro it give me a sintax error.
Your help will be really appreciated.
CirasaEric's code worked for lots of passwords, but some weren't working for me. Looking at the code, range 94-103 have letters in it that work. I see 127 up to 194 to be skipped, with an offset of 68.
//Checksum between 127 and 194 result in bad chars. Barcode chars begin in this font again at 196.
if (sum > 126 && sum < 195)
sum += 68;
Lots of text inputs, not passwords.
I translated CirasaEric's code into VBA and added Aki7 extra.
I don't actually know what they are talking about in those 2 cases and didn't run into any problems testing it out but I only used it on simple combinations of letters and numbers.
Function Code128(Code As String) As String
'Application.Volatile
Code128 = Chr(204) & Code
Dim encoded As Long
encoded = 104
Dim length As Long
Dim i As Long
i = 0
Do While i < Len(Code)
encoded = encoded + (Asc(Mid(Code, i + 1, 1)) - 32) * (i + 1)
i = i + 1
Loop
encoded = encoded Mod 103
encoded = encoded + 32
If encoded > 94 And encoded < 103 Then encoded = encoded + 105
If encoded > 127 And encoded < 194 Then encoded = encoded + 68
Code128 = Code128 & Chr(encoded) & Chr(206)
End Function
Small edits.
I have removed "If encoded > 94 And encoded < 103 Then encoded = encoded + 105" this line and changed the next line to
If encoded => 127 And encoded <= 194 Then encoded = encoded + 68
Translated DBrackenWork code to T-SQL. Tested and works for 128A characters.
Originally there were 104 instead of 103 constant and 204 instead of 203, however CHAR(204) is for no understandable reason copy-pastable correctly. Maybe due to language/collation setting of our server. So I falled back to Start A...
Enjoy the code:
ALTER FUNCTION [dbo].[Code128_encode]
(
-- Add the parameters for the function here
@TextToEncode varchar(max)
)
RETURNS varchar(max)
AS
BEGIN
-- Declare variables
DECLARE @i int = LEN(@TextToEncode) -- Pointer over characters to encode
DECLARE @Check int = 103 -- Sum for modulo computation; assumes Start Code A used
-- adding 32 makes it character ASCII number of check digit
-- Cycle over all payload characters; runs from end backwards to compute LEN(@TextToEncode) only once
-- assumes Start Code was added (* 1 multiplier) in @Check declaration
WHILE (@i > 0)
BEGIN
SET @Check = @Check + ((ASCII(SUBSTRING(@TextToEncode, @i, 1 ))-32) * @i)
SET @i = @i-1
END
-- Compute modulo and make ASCII code from value
SET @Check = (@Check % 103) + 32
IF (@Check >= 127) -- Check can never be greater than 102+32=134
SET @Check = @Check + 68
-- Return the resulting barcode: Start Code A + text + checkdigit + Stop pattern (Stop + Final bar)
RETURN CHAR(203) + @TextToEncode + CHAR(@Check) + CHAR(206) -- In ideal world this should work...
END
Bonus update - Here it is in modern Excel with no VBA needed. Target text in A1.
=CHAR(204)&A1&CHAR(LET(ENCODED,MOD(104+SUM((CODE(MID(A1,SEQUENCE(,LEN(A1),,1),1))-32)*SEQUENCE(,LEN(A1),,1)),103)+32,ENCODED+IF(AND(ENCODED>=127,ENCODED<=194),68,0)))&CHAR(206)
stumpled uppon this great work from zebu.
Can someone help me with the STOP character?
CHAR(206) like in DBrackenWork's formula delivers the french OE for me:
https://www.pic-upload.de/view-37389527/Bildschirmfoto2024-07-23um15.06.04.png.html
My formula looks like this (german)
=ZEICHEN(204)&A1&ZEICHEN(LET(ENCODED;REST(104+SUMME((CODE(TEIL(A1;SEQUENZ(;LÄNGE(A1);;1);1))-32)*SEQUENZ(;LÄNGE(A1);;1));103)+32;ENCODED+WENN(UND(ENCODED>=127;ENCODED<=194);68;0)))&ZEICHEN(206)
The issue seems the CHAR(206)/ZEICHEN(206).
Thank you
jpxr
tried with version #2 from zebu's website (https://grandzebu.net/informatique/codbar-en/code128.htm#Version)
START and STOP signs are just blank squares. thus, no luck either with V2
Found a solution:
download the latest version:
https://grandzebu.net/informatique/codbar-en/code128.htm#Version
Start Ñ 132
Stop Ó 238
german Excel formula:
=ZEICHEN(132)&A2&ZEICHEN(LET(ENCODED;REST(104+SUMME((CODE(TEIL(A2;SEQUENZ(;LÄNGE(A2);;1);1))-32)*SEQUENZ(;LÄNGE(A2);;1));103)+32;ENCODED+WENN(UND(ENCODED>=127;ENCODED<=194);68;0)))&ZEICHEN(238)