# VBForums CodeBank > CodeBank - Visual Basic 6 and earlier >  VB6 - Code128 A,B and C

## CVMichael

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:

----------


## coolcurrent4u

> 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?

----------


## CVMichael

The code generates the barcode images...

----------


## coolcurrent4u

oh sorry, i misunderstood u, that correct thanks anyways

----------


## berserkk

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!

----------


## berserkk

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.

----------


## Feiten

Is there a way to print UCC/EAN-128 in Visual Basic 6 ? 

I'm trying to find it, but no solutions...

----------


## berserkk

see http://www.barcodeisland.com/uccean128.phtml :




> ... 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)

----------


## Feiten

> see http://www.barcodeisland.com/uccean128.phtml :
> 
> 
> 
> So just use the code given by CV Michael (but beware of the missing start character issue)


Thanks a lot, berserkk. 

I'll take a look at this.

----------


## Pcunha

CV micheal,

thank you very much for the code. I adapted it to a VBA class to use in excel.

But i must warn you that tha code has some bugs:

Line 229 of the .cls file:
AddEntry 76, Chr(12), "I", "76", "2 2 1 1 1 4" ' FF
Muse be:
AddEntry 76, Chr(12), "l", "76", "2 2 1 1 1 4" ' FF

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

----------


## VaughanJer

Paulo,

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




> CV micheal,
> 
> thank you very much for the code. I adapted it to a VBA class to use in excel.
> 
> But i must warn you that tha code has some bugs:
> 
> Line 229 of the .cls file:
> AddEntry 76, Chr(12), "I", "76", "2 2 1 1 1 4" ' FF
> Muse be:
> ...

----------


## emcourtney

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

    Me.barcode.Value = code.Code128_Str(Str)
End Sub

Good luck,

----------


## k9aland

Hello, my first post in this forum!

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!

Magnus

----------


## CVMichael

I am not sure what step by step information you need... Do you have any specific questions?

----------

