How print barcode without digits with ZPL lang - zpl

How print code128 barcode without digit, just image of barcode?
my example with digits:
^FO20,20
^BCN,50,Y,N
^FD1234567890^FS

You need to reference the ZPL II Programming Guide
^BC is for printing Code 128 Bar Codes
Format: ^BCo,h,f,g,e,m
o = orientation
h = height
f = interpretation line
g = interpretation line above code
e = UCC check digit
m = mode
You are setting f to Y, change that to N.
^BCN,50,N,N

Related

Generating unique non-similar codes with validation

I know there are similar questions so please bear with me.
I wish to generate approximately 50K codes for people to place orders - ideally no longer than 10 chars and can include letters and digits. They are not discount codes so I am not worried about people trying to guess codes. What I am worried about is somebody accidentally entering a wrong digit (ie 1 instead of l or 0 instead of O) and then the system will fail if by chance it is also a valid code.
As the codes are constantly being generated, ideally I don't want a table look-up validation, but an formula (eg if it contains an A the number element should be divisable by 13 or some such).
Select some alphabet (made of digits and letters) of size B such that there are no easy confusions. Assign every symbol a value from 0 to B-1, preferably in random order. Now you can use sequential integers, convert them to base B and assign the symbols accordingly.
For improved safety, you can append one or two checksum symbols for error detection.
With N=34 (ten digits and twenty four letters 9ABHC0FVW3YGJKL1N2456XRTS78DMPQEUZ), 50K codes require codes of length only four.
If you don't want the generated codes to be consecutive, you can scramble the bits before the change of base.
Before you start generating random combinations of characters, there are a couple of things you need to bear in mind:
1. Profanity
If your codes include every possible combination of four letters from the alphabet, they will inevitably include every four-letter word. You need to be absolutely sure that you never ask customers to enter anything foul or offensive.
2. Human error
People often make mistakes when entering codes. Confusing similar characters like O and 0 is only part of the problem. Other common mistakes include transposing adjacent characters (e.g. the → teh) and hitting the wrong key on the keyboard (e.g., and → amd)
To avoid these issues, I would recommend that you generate codes from a restricted alphabet that has no possibility of spelling out anything unfortunate, and use the Luhn algorithm or something similar to catch accidental data entry errors.
For example, here's some Python code that generates hexadecimal codes using an alphabet of 16 characters with no vowels. It uses a linear congruential generator step to avoid outputting sequential numbers, and includes a base-16 Luhn checksum to detect input errors. The code2int() function will return −1 if the checksum is incorrect. Otherwise it will return an integer. If this integer is less than your maximum input value (e.g., 50,000), then you can assume the code is correct.
def int2code(n):
# Generates a 7-character code from an integer value (n > 0)
alph = 'BCDFGHJKMNPRTWXZ'
mod = 0xfffffd # Highest 24-bit prime
mul = 0xc36572 # Randomly selected multiplier
add = 0x5d48ca # Randomly selected addend
# Convert the input number `n` into a non-sequential 6-digit
# hexadecimal code by means of a linear congruential generator
c = "%06x" % ((n * mul + add) % mod)
# Replace each hex digit with the corresponding character from alph.
# and generate a base-16 Luhn checksum at the same time
luhn_sum = 0
code = ''
for i in range(6):
d = int(c[i], 16)
code += alph[d]
if i % 2 == 1:
t = d * 15
luhn_sum += (t & 0x0f) + (t >> 4)
else:
luhn_sum += d
# Append the checksum
checksum = (16 - (luhn_sum % 16)) % 16
code += alph[checksum]
return code
def code2int(code):
# Converts a 7-character code back into an integer value
# Returns -1 if the input is invalid
alph = 'BCDFGHJKMNPRTWXZ'
mod = 0xfffffd # Highest 24-bit prime
inv = 0x111548 # Modular multiplicative inverse of 0xc36572
sub = 0xa2b733 # = 0xfffffd - 0x5d48ca
if len(code) != 7:
return -1
# Treating each character as a hex digit, convert the code back into
# an integer value. Also make sure the Luhn checksum is correct
luhn_sum = 0
c = 0
for i in range(7):
if code[i] not in alph:
return -1
d = alph.index(code[i])
c = c * 16 + d
if i % 2 == 1:
t = d * 15
luhn_sum += (t & 0x0f) + (t >> 4)
else:
luhn_sum += d
if luhn_sum % 16 != 0:
return -1
# Discard the last digit (corresponding to the Luhn checksum), and undo
# the LCG calculation to retrieve the original input value
c = (((c >> 4) + sub) * inv) % mod
return c
# Test
>>> print('\n'.join([int2code(i) for i in range(10)]))
HWGMTPX
DBPXFZF
XGCFRCN
PKKNDJB
JPWXNRK
DXGGCBR
ZCPNMDD
RHBXZKN
KMKGJTZ
FRWNXCH
>>> print(all([code2int(int2code(i)) == i for i in range(50000)]))
True

Creating a checkerboard using Ruby and "\n" not disappearing

I feel as if I am close to a solution and have been tinkering around with this as a newb for some time. Why, for some reason, are my "\n"'s not disappearing when outputted for "next line" and the output has unneeded white space?
Task: Write a function which takes one parameter representing the dimensions of a checkered board. The board will always be square, so 5 means you will need a 5x5 board.
The dark squares will be represented by a unicode white square, while the light squares will be represented by a unicode black square (the opposite colors ensure the board doesn't look reversed on code wars' dark background). It should return a string of the board with a space in between each square and taking into account new lines.
An even number should return a board that begins with a dark square. An odd number should return a board that begins with a light square.
The input is expected to be a whole number that's at least two, and returns false otherwise (Nothing in Haskell).
I am close, and here is what I have so far:
def checkered_board(dimension)
black = "\u25A1 "
white = "\u25A0 "
checkboard = nil
checker_array = []
if dimension < 2 or dimension.is_a? String
return false
else
count = dimension
while count <= dimension && count > 0
if count % 2 == 0
checkboard = ("\u25A1 \u25A0" + "\n")
checker_array << checkboard
count -= 1
else
checkboard = ("\u25A0 \u25A1" + "\n")
checker_array << checkboard
count -= 1
end
end
end
checkboard = checker_array.join(" ")
p checkboard
end
Here is the TDD specs:
Test.assert_equals(checkered_board(0), false)
Test.assert_equals(checkered_board(2), "\u25A1 \u25A0\n\u25A0 \u25A1")
Note: Hidden specs demonstrate that it should respond with false if dimension is not an integer. .is_a? String and .is_a? Integer is not working for me too.
Output appears like so, and is not appearing even:
□ ■
■ □
Thanks for any and all help :).
Try changing:
if dimension < 2 or dimension.is_a? String
to
if !dimension.is_a?(Integer) || dimension < 2
The left most test will be done first. At the moment, if dimension is a String, it is first compared with 2 - which will raise an error - before it is tested as to whether it is a String. You need to check the type of object before you compare it with another object.
Also, I think the check should be whether dimension is not an Integer, rather than whether it is a String. For example, in your original code, what would happen if dimension was an Array?
The join method will concatenate the elements with a space character inserted between them. So this line from the program:
checkboard = checker_array.join(" ")
will result in this string:
"\u25A1 \u25A0\n \u25A0 \u25A1"
Omitting the argument to join should produce the expected output, ie.:
checkboard = checker_array.join
Refer to the documentation on the Array join method.

ZPL Code 128 multiple subset barcode isn't printing as expected

I'm using the following command to print a multi-subset (FS1-128) Code 128 barcode in ZPL:
^XA
^FO600,250
^BY3
^BCR,175,N,N,N,N
^FD>;>8019931265099999891>7T77>5000126101000600209^FS
^XZ
I'm trying to generate:
Start C + FNC1 + 019931265099999891 + Code A + T77 + Code C + 000126101000600209
When I print it out, the barcode reads:
Start C + FNC1 + 019931265099999891 + Code A + 77 + Code C + 000126101000600209 + 95 + STOP
I know that ZPL added the 95 (symbol check) and STOP to complete the barcode. The Code A section is all wrong though. The T is missing, and the 7s are coded as a pair (i.e. Code C), not single digits. It's like it's printed the Code A, but neglected to switch to that subset...
More info: I'm printing to a Zebra GX420d and a Zebra LP 2844-Z.
This is a hacky fix, but it works.
To get the subset A portion ("T77") of my mostly subset C barcode to print correctly, I translated the individual subset A characters to their subset C equivalents and used those values instead.
To generate:
Start C + FNC1 + 019931265099999891 + Code A + T77 + Code C + 000126101000600209
My input string ended up being:
Start C + FNC1 + 019931265099999891 + Code A + 522323 + Code C + 000126101000600209
Which in ZPL is:
^FD>;>8019931265099999891>7522323>5000126101000600209^FS

Visual Basic: How to only accept 0 and 1?

sorry to be a bother but I have been working on a binary addition code for some time now and I have nearly gotten it finished. However, there is still a minor problem that I have been struggling to fix involving valid input.
In this code, it should find the length of the binary input and convert each character to denary before adding them up. If an input that is not 0 or 1 is entered then it should reject the input and tell the user to restart the code.
The problem I am having is that when erroneous data is entered, the code will simply crash instead of going to the line of code where it will tell the user that it is invalid input. Does anyone know a solution to my problem?
Note: I have repeated this code twice for both binary values being entered.
The section of the program where I believe the error is currently looks like this:
Y is what I am using to convert the value to denary so I can add binary values together in denary form. [integer]
binarya is the input value. [string]
chart is the current character being converted. [integer]
current is the current character converted to denary. [integer]
denarya is the denary value of binarya. [integer]
Y = 1
binarya = console.readline
Len(binarya)
For i = Len(binarya) to 1 step -1
chart = Mid(binarya, i, 1)
If chart <> "1" and chart <> "0" then
Console.readline("This is not valid BINARY input, restart the code!")
Console.readline
End if
current = chart * 1 * Y
denarya = denarya + current
Y = Y * 2
Next
You should write the message, not read it. Also, you should return after you read it.
Y = 1
binarya = console.readline
Len(binarya)
For i = Len(binarya) to 1 step -1
chart = Mid(binarya, i, 1)
If chart <> "1" and chart <> "0" then
Console.WriteLine("This is not valid BINARY input, restart the code!")
Console.ReadLine
Return
End if
current = chart * 1 * Y
denarya = denarya + current
Y = Y * 2
Next

Small basic random letters

I'm batch file programmer but I'm experimenting with Small Basic. I know how to generate random numbers as a variable:
Math.getrandomnumber(number)
but I'm not sure how to generate random letters
Here you are! Like Tobberoth said, use text.GetCharacter for this. here is the code:
RandNum = Math.GetRandomNumber(25) + 65 'Get a number between 65 and 90 (See ASCII)
RandText = Text.GetCharacter(RandNum)
TextWindow.WriteLine(RandText)
I don't really know, but if you are dealing with just a few letters, for example ABC, I would do this:
Code:
number = Math.GetRandomNumber(3)
If number = 1 Then
letter = A
Elseif number = 2 Then
letter = B
Elseif number = 3 Then
letter = C
EndIf
This should help.
Just to round out the list of suggestions, you can do random anything using arrays.
hex[0] = "0"
hex[1] = "1"
hex[2] = "2"
...
hex[10] = "A"
hex[11] = "B"
hex[12] = "C"
hex[13] = "D"
hex[14] = "E"
hex[15] = "F"
randomHexDigit = hex[Math.GetRandomNumber(16) - 1]
The above will produce a random hex digit from the array.

Resources