B4J Tutorial Barcodes - QR Codes, PDF417, Aztec Codes, Code11, Code39, Code93, EAN8, EAN13, and Code128

This is my first attempt at B4J. Have not tried to do anything special to the layout etc. The aim was to get back the correct binary strings to draw Code11, Code39, Code93, EAN8 and EAN13 barcodes with. All the code are in the main module as well as modules for each of the types of barcodes. The B4J project also includes a class called StringUtilities that the project makes use of. This class contains 38 string manipulation methods making use of inline java code.

Each of the barcode modules return a binary string (1's and 0's). You need to draw an equal sized bar (width and height) for each 1 (black) and for each 0 (white). For eg, 11 will be two black bars next to one another, 10 will be a black bar followed by a white bar, 00 will be two consecutive white bars, and 01 will be a white bar followed by a black bar.

The barcodes generated for EAN8 and EAN13 includes the parity bits - take note that the label next to them only shows the original input message for EAN8 and EAN13 barcodes. You can amend the code in the B4J project to your own liking and for eg return an array of strings that contains for eg (1) the binary string of the input message and (2) the parity bit/number for EAN8 or EAN13 barcodes. Very simple to do and I leave it up to whoever wants to use this project.

Have not fully amended the error checking for valid input messages. Simple to do and I leave it up to whoever wants to use this B4J project.

This project is based on my B4A project that you can find here. Just busy amending it so that it can be used in B4J. Have tested/scanned each of Code11, Code39, Code93, EAN8 and EAN13 with QRCPV4 that you can find here.

I will add Code128, Aztec Codes, PDF417, and QR Codes (as what I have inside the B4A project) as and when time permits.

No internet connection is required to generate the barcodes - all the code are in the code modules.

Edit: see project in post #9. It generates QRCodes, PDF417, Aztec Codes, Code11, Code39, Code93, EAN8, EAN13, and Code128

1.png
 

Attachments

  • BARCODES.zip
    181.9 KB · Views: 1,410
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Replace the code in Sub Button1_MouseClicked (EventData AsMouseEvent) with the code below

B4X:
Sub Button1_MouseClicked (EventData As MouseEvent)

    Label1.Visible = True
    Label2.Visible = True
    Label3.Visible = True 
    Label4.Visible = True
    Label5.Visible = True

    Dim binstring As String = ""
    Dim msg, prefix, postfix As String
    msg = "12345"
    prefix = "A"
    postfix = "B"
    binstring = Code11.Draw_Code11(msg, prefix, postfix)
    Log("binstring Code11 = " & binstring)
    draw_barcode_Code11(binstring)
    Label1.Text = prefix & msg & postfix & Chr(10) & Chr(13) & "Code 11 Barcode"
 
    msg = "987654"
    binstring = Code39.Draw_Code39(msg)
    Log("binstring Code39 = " & binstring)
    draw_barcode_Code39(binstring) 
    Label2.Text = msg & Chr(10) & Chr(13) & "Code 39 Barcode"
 
    msg = "234567"
    binstring = Code93.Draw_Code93(msg)
    Log("binstring Code93 = " & binstring) 
    draw_barcode_Code93(binstring)
    Label3.Text = msg & Chr(10) & Chr(13) & "Code 93 Barcode"
 
    msg = "1234567"
    binstring = EAN8.Draw_EAN8(msg)
    Log("binstring EAN8 = " & binstring)     
    draw_barcode_EAN8(binstring)     
    Label4.Text = msg & Chr(10) & Chr(13) & "EAN 8 Barcode"
 
    msg = "123456789012"
    binstring = EAN13.Draw_EAN13(msg)
    Log("binstring EAN13 = " & binstring)     
    draw_barcode_EAN13(binstring) 
    Label5.Text = msg  & Chr(10) & Chr(13) & "EAN 13 Barcode" 
 
End Sub

...and then you should get this (indicating the type of barcode inside the label as well):

2.png
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
The attached project adds Aztec Codes (layer 1 to layer 11) to the barcodes already posted in the previous projects. Use something like NeoReader to scan the PDF417 and Aztec codes with.

6.png
 

Attachments

  • BARCODES_add_AztecCode.zip
    213.1 KB · Views: 811

Johan Schoeman

Expert
Licensed User
Longtime User

Johan Schoeman

Expert
Licensed User
Longtime User
The attached project adds QR Codes (Version 1 to Version 40) to the barcodes already posted in the previous projects. Use something like NeoReader or this to scan the QR Codes with.

I will try and spend a bit of additional time on it to redo the drawing of the 1D barcodes by adding their code back into the various code modules. Will also add the possibility to change the fore color and back color of the barcodes as well as the size of the bars in the 1D barcodes and the modules in the 2D codes.

(Can I say that I am reasonably proud of my very first B4J project...:cool:. There are 10 380 lines of code in the code modules to generate these barcodes with)

7.png
 

Attachments

  • BARCODES_add_QRcode.zip
    239.6 KB · Views: 1,111
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Attached project refers:
1. Have moved the drawing methods of the 1D barcodes into the applicable code modules
2. Have added functionality to accommodate a foreground and background color
3. Have added functionality to accommodate 1D bar widths and 2D module sizes.

The End.

8.png
 

Attachments

  • BARCODES_add_color_bar_width_and_module_size.zip
    239.9 KB · Views: 1,079

rboeck

Well-Known Member
Licensed User
Longtime User
Hi johan,

currently i want to try your last examples, but i can't compile it in debug mode; in release mode it works without problems. Maybe my java options are not usefull?
Thanks!
Reinhard
 

Attachments

  • barcode.png
    barcode.png
    8.7 KB · Views: 878

Johan Schoeman

Expert
Licensed User
Longtime User
Hi johan,

currently i want to try your last examples, but i can't compile it in debug mode; in release mode it works without problems. Maybe my java options are not usefull?
Thanks!
Reinhard
The code modules that have the code for PDF417, Aztec Codes, and QR Codes are lengthy and will not compile in debug mode (as per Erel's post above). You will need to break these 3 code modules into a number of smaller code modules to compile it in debug mode. Shout if you need some assistance - will gladly assist.
 
Last edited:

rboeck

Well-Known Member
Licensed User
Longtime User
Hi johan,

i have tried to reduce the size of some subs and now i have a running debug version of qrcode.bas. I have splitted the longest sub in four parts. Maybe you could take a look on it and check it under some circumstances before some one else use a maybe problematic version.
 

Attachments

  • QRcode.bas
    177.3 KB · Views: 1,107

Johan Schoeman

Expert
Licensed User
Longtime User
Hi johan,

i have tried to reduce the size of some subs and now i have a running debug version of qrcode.bas. I have splitted the longest sub in four parts. Maybe you could take a look on it and check it under some circumstances before some one else use a maybe problematic version.
Hi @rboeck

Have not downloaded it yet. Is it working for you after you have done the split? Can you now compile it in debug mode? From your post above it seems to me as if you have it working. I have written the QR code project in such a way that it will automatically decide what version QR code should be used based on the input message. So, if you want to test it then give it a fairly long input message and pass the required error level and mask pattern to apply. If it then scans - well, Bob's your uncle...will nevertheless download and test sometime tonight. But well done on the split!
 
Last edited:

Johan Schoeman

Expert
Licensed User
Longtime User
Hi johan,

i have tried to reduce the size of some subs and now i have a running debug version of qrcode.bas. I have splitted the longest sub in four parts. Maybe you could take a look on it and check it under some circumstances before some one else use a maybe problematic version.
Your mod to the code seems to be working 100%. Have just added a long string of data that returned a Version 10 QR Code and it scans perfectly. Noticed your changes to the various select_block subs that the original sub was broken into. ;)
 

rboeck

Well-Known Member
Licensed User
Longtime User
I tried first to reduce the size with optimization; but after many tries the problem in debug mode persists; so it changed my strategy and splitted the biggest sub and this worked. I could try to use two dimensional array for ver, but it is much work and the code is already working.
Thanks for your work,
Reinhard
 

rboeck

Well-Known Member
Licensed User
Longtime User
I could not resist to further optimize and shorten your code: now i could reduce it to 35% of the original size; as long as i see, the functionality is still alive. The biggest thing was to get the values in an 2 dimensional array; then many things could be extremly shortened. All select_clock lines are now 42 lines.
When i begin, i also had no idea how to make it; but this project leads me to learn how to use two dimensional arrays.
Reinhard
 

Attachments

  • QRcode.bas
    58.5 KB · Views: 868

JTmartins

Active Member
Licensed User
Longtime User
Rboeck, I just tried your code as in previous post, and I still get a "Error to large for try statement..." in debug mode.

Can you compile it in debug mode ? (B4J 4.01 and jdk1.8.0_45 here)

Thanks

JM
 

rboeck

Well-Known Member
Licensed User
Longtime User
Hi JTmartins,

i was unprecise in my previous posts - my interest was primary in qr code generation and my work only changed this module. In my working project i have remarked pdf417 and actec code (line 124 to line 141) and removed the modules. In this form it compiles in debug mode. I use B4J 4.2 beta and jdk1.8.0_65
 

skeedsr

Member
hi johan thank for the exhample, i have some issue, in de code 128 i cant write long word like "01aaviocomm12".

I look that axept only 8 caracter, but usually the 128 code axept more.

thanks!

Livio
 
Top