I wrote this code a while ago, and I tested it with an actual bar code scanner.
The code detects automatically what subset to use, A, B or C.
For example, if you use only numbers, it will use Code128C, and if you mix, it will change the subset within the barcode. For example, if you use a string like "123456789abcdef", it will start with Code128C, then when it reaches the alpabet characters, it will change to Code128B in the same barcode.
Here's a screen shot of the sample application:
Last edited by CVMichael; Jun 6th, 2009 at 09:26 PM.
I wrote this code a while ago, and I tested it with an actual bar code scanner.
The code detects automatically what subset to use, A, B or C.
For example, if you use only numbers, it will use Code128C, and if you mix, it will change the subset within the barcode. For example, if you use a string like "123456789abcdef", it will start with Code128C, then when it reaches the alpabet characters, it will change to Code128B in the same barcode.
Here's a screen shot of the sample application:
CV micheal this is great, but how do u et the images into your program, is it from the barcode scanner or from a desktop scanner?
Programming is all about good logic. Spend more time here
Hi, great job with this!
one problem, i'm trying to print the following barcode:
23020505543820
but it doesn't seem to print the start code properly, i think the first double width bar is missing?
any help would be appreciated!
in fact in the example image all of those barcodes are missing the start characters.
i think what happens is that the barcode prints the first 2 characters as white, and therefore it is is invisible.
I wasn't smart enought to figure out how to properly fix it, but found a workaround:
in function Code128_Print of clsCode128.cls
change the line:
Ret = Replace(Code128_Str(Str), " ", "")
to
Ret = "11" & Replace(Code128_Str(Str), " ", "")
That way the characters "11" will print white, but the rest of the barcode including start characters will print properly.
... a UCC/EAN-128 symbol is, in fact, a Code 128 bar code. The UCC/EAN-128 symbol has the following Code 128 structure:
1) A Code-128 Start character (A, B, or C).
2) A Code-128 FNC1 character (character 102).
3) Application Identifier (from AI table corresponding to data to be encoded).
4) Data to be encoded (format depends on AI).
5) A Code-128 checksum character.
So just use the code given by CV Michael (but beware of the missing start character issue)
Line 311 of the .cls file:
If CodeArr(ArrIndex).BSet = CurrChar And ((SCode = eCode128_CodeSetC And CodeArr(ArrIndex).CSet <> CurrChar) Or (SCode = eCode128_CodeSetC And CodeArr(ArrIndex).ASet <> CurrChar)) Then
Must be:
If CodeArr(ArrIndex).BSet = CurrChar And ((SCode = eCode128_CodeSetC And CodeArr(ArrIndex).CSet <> CurrChar) Or (SCode = eCode128_CodeSetA And CodeArr(ArrIndex).ASet <> CurrChar)) Then
I've also made some considerable changes in order to use the GrandZebu free code128 font. This way you can embedd this class in a VBA and ise it on the M$ excel or word.
The new code follows in attach.
Thanks
Paulo Cunha
Last edited by si_the_geek; May 16th, 2011 at 01:15 PM.
Reason: removed "advertising" link
I am trying to use the code you provided in VB 6.5 (within MS Access 2003), and I get a "Run-time error '9': Subsript out of range" error message on line 247:
Select Case CodeType
Case eCode128_CodeSetA
For K = 0 To UBound(CodeArr)
If Char = CodeArr(K).ASet Then Exit For
Next K
Case eCode128_CodeSetB
For K = 0 To UBound(CodeArr)
If Char = CodeArr(K).BSet Then Exit For
Next K
Case eCode128_CodeSetC For K = 0 To UBound(CodeArr)
If Char = CodeArr(K).CSet Then Exit For
Next K
End Select
Have you seen this before? I am using the font from grandzebu.net that your reference in the top of the code.
Thanks!
Jeremy
Originally Posted by Pcunha
CV micheal,
thank you very much for the code. I adapted it to a VBA class to use in excel.
Line 311 of the .cls file:
If CodeArr(ArrIndex).BSet = CurrChar And ((SCode = eCode128_CodeSetC And CodeArr(ArrIndex).CSet <> CurrChar) Or (SCode = eCode128_CodeSetC And CodeArr(ArrIndex).ASet <> CurrChar)) Then
Must be:
If CodeArr(ArrIndex).BSet = CurrChar And ((SCode = eCode128_CodeSetC And CodeArr(ArrIndex).CSet <> CurrChar) Or (SCode = eCode128_CodeSetA And CodeArr(ArrIndex).ASet <> CurrChar)) Then
I've also made some considerable changes in order to use the GrandZebu free code128 font. This way you can embedd this class in a VBA and ise it on the M$ excel or word.
Did you instantiate the class? CodeArr isn't defined until the Class_Initialize() method is run. If you're using VBA, like me, add the .cls file as a class module then, in your form or report or whatever do something like:
Private Sub blNumber_Exit(Cancel As Integer)
Dim Str As String
Dim code As cls_Code128
Str = Me.blNumber.Value
Set code = New cls_Code128
As I am beginner that are in my first few months of VBA coding, I need some help! I have database that I would like to print code 128-c barcode on access report. I did make this one to work http://www.accessforums.net/showthread.php?t=33878 (but that one only gives code 128-b).
As my database will be working in highly secured enviorment, I have no possibility to use an font for that. Please help out with some " step by step" explanation!