Recently we came across an issue with BarcodeCode128 barcodes - when using a tilde character (~) within a BarcodeCode128 barcode in AX the resulting barcode can be unreadable by scanners.
The reason for this is that Code128 has three different code sets associated with it – using an escape character in the barcode string to switch between these code sets. Different applications do this in different ways using different characters, in AX we use the tilde character to inform the program that we want to use another code set.
Once AX has picked up a tilde it expects to receive a specific value next in the barcode string: c, d, e, f, or g, these are the control characters which have the ASCII numerical value of 99-105 which will change the code set and create the first few bars of the barcode which tell the reader which code set is being used and continue on to create a new barcode.
If a different character is placed after the tilde (anything other than c, d, e, f, or g) then it never finds the desired code set, doesn’t create the first few lines of the barcode that tell the reader what it is supposed to be reading and leads to an unreadable barcode – it does not produce an error, it will simply create a corrupted barcode, which is why it is important to understand this process.
Here you can see the corrupted barcode, on the right hand side they are identical, however the beginning has been entirely left out in the ~A example:
With the barcode string "~A":
With the barcode string "~gA":
When entering the value ~gA (~ = escape character, g = control character instigating code set B) then barcode is readable and displays ‘A’ as with the second example above.It is important to either keep tildes out of barcodes where possible or – if you must have tildes in your barcode strings then you would need to write a modification, bear in mind that any changes here may cause further problems in the future when using the BarcodeCode128 class for its original purpose. The specific place where this logic is used is: Classes\BarcodeCode128.encodeString()
Specifically the following line where the escChar parameter holds the value 126 (tilde):