Author Topic: Code to print out a barcode on a label printer works well  (Read 3808 times)

0 Members and 1 Guest are viewing this topic.

Offline Chris80194

  • Newbie
  • Posts: 42
    • View Profile
Code to print out a barcode on a label printer works well
« on: July 28, 2019, 06:54:11 pm »
I created this so that I could print barcodes for powder coat paint which can expire with some time also the larger program has a serial number part to make these unique to each box.
PRINT "--------------------------------------------------------------"
PRINT "Serial " + DATAPASS1$ + "                  Use By "; DATAPASS2$    Title$ is a title that you probably wont use
PRINT DATAPASS3$
PRINT DATAPASS4$
PRINT "||| ||| || |||||||| |||||| |||||| ||||| | |||||| ||||||| |||||"
PRINT "--------------------------------------------------------------"
The basic label will print but the actual label messes up if you add a pause before the print out you get a ? in the label which is not desirable.  Which is why I made the above sample.  Any ideas how to remove that and get a pause?  I guess I could color the ? white but then how do you know to hit a key to proceed???

Code: QB64: [Select]
  1. PRINT "Barcode Printer code"
  2. PRINT "Tested and tweaked to use the "
  3. PRINT "Label designer for the Brother 201 (29mm x 90mm or 1-1/7 x 3-1/2)"
  4. PRINT "The Zebra, ZDesigner LP 2844 looks to be compatible too. no modifications made."
  5. PRINT "If you do not have it already You will need to search for free3of9x.ttf"
  6. PRINT "Redable text uses the windows Arial.ttf"
  7. PRINT "Should work with other Windows Font and the 128 code but not needed for my use"
  8. PRINT "Expire print out is formated for a date mm/dd/yyyy or a 10 character description"
  9. PRINT "What data do you want as the barcode data"
  10. INPUT "It is best not to exceed 9 characters ", DATAPASS1$
  11. DATAPASS1$ = "*" + DATAPASS1$ + "*"
  12. INPUT "Enter an Expireation date ", DATAPASS2$
  13. INPUT "Enter a Description Line 1 ", DATAPASS3$
  14. INPUT "Enter a Description Line 2 ", DATAPASS4$
  15. PRINT "--------------------------------------------------------------"
  16. PRINT "Serial " + DATAPASS1$ + "                         Use By "; DATAPASS2$
  17. PRINT DATAPASS3$
  18. PRINT DATAPASS4$
  19. PRINT "||| ||| || |||||||| |||||| |||||| ||||| | |||||| ||||||| |||||"
  20. PRINT "--------------------------------------------------------------"
  21. INPUT "As soon as you press enter the label will print", a
  22. 'FFONT$ = "free3of9x.ttf": FFSize = 120
  23. 'EFONT$ = "Arial.ttf": EFSize = 60
  24. 'AFONT$ = "Arial.ttf": AFSize = 60
  25. 'PageWidth = 216 * 10
  26. 'PageHeight = 279 * 10
  27.  
  28. 'Label designer for the Brother 201 (29mm x 90mm or 1-1/7" x 3-1/2") / Zebra ZDesigner LP 2844 looks compatible.
  29. FFONT$ = "free3of9x.ttf": FFSize = 240
  30. EFONT$ = "Arial.ttf": EFSize = 40
  31. AFONT$ = "Arial.ttf": AFSize = 40
  32. PageWidth = 110 * 10 'maximized tweaks for whole label
  33. PageHeight = 29 * 10 'Max is already set do not change.
  34.  
  35. Colum = 10
  36. a = 0
  37. SCREEN _NEWIMAGE(PageWidth, PageHeight, 13)
  38. _DEST Page&: CLS _RGB(1, 1, 1), _RGB(256, 256, 256): _DEST 0 'make background white to save ink!
  39. F& = _LOADFONT(FFONT$, FFSize)
  40. E& = _LOADFONT(EFONT$, EFSize)
  41. A& = _LOADFONT(AFONT$, AFSize)
  42.  
  43. COLOR _RGB(1, 1, 1), _RGB(256, 256, 256): _PRINTSTRING (Colum, 45), DATAPASS1$ ' Print upc bars on bottom of label
  44.  
  45. COLOR _RGB(1, 1, 1), _RGB(256, 256, 256): _PRINTSTRING (400, 0), Title$ ' Print Line 1 description
  46.  
  47. COLOR _RGB(1, 1, 1), _RGB(256, 256, 256): _PRINTSTRING (Colum, 35), DATAPASS3$ ' Print Line 2 ProductInventory description
  48. COLOR _RGB(1, 1, 1), _RGB(256, 256, 256): _PRINTSTRING (Colum, 68), DATAPASS4$ ' Print Line 3 ProductInventory description
  49.  
  50. keep = LEN(DATAPASS1$): DATAPASS1$ = MID$(DATAPASS1$, 2, keep - 2)
  51. COLOR _RGB(1, 1, 1), _RGB(256, 256, 256): _PRINTSTRING (Colum, 0), "Serial " + DATAPASS1$ ' Print upc bar information above bar scan font
  52. IF DATAPASS2$ <> "" THEN COLOR _RGB(1, 1, 1), _RGB(256, 256, 256): _PRINTSTRING (725, 0), "Use By " + DATAPASS2$ ' Print Product Expiry Date
  53.  
  54. _PRINTIMAGE 0 'print screen page on printer
  55.  
« Last Edit: July 28, 2019, 06:59:08 pm by Chris80194 »

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Code to print out a barcode on a label printer works well
« Reply #1 on: July 28, 2019, 10:19:01 pm »
Is the ? from an INPUT? If so, how is it getting on label from printer or am I misunderstanding?

Quote
but then how do you know to hit a key to proceed???

How about an audio cue like a beep or sound, of a speech synthesized, "Proceed"
« Last Edit: July 28, 2019, 10:21:51 pm by bplus »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Code to print out a barcode on a label printer works well
« Reply #2 on: July 29, 2019, 09:08:33 am »
After _PRINTIMAGE on row 63 you call new SCREEN 0
on row 42 you call virtual screen Page&, you set badly backgroundcolor (maximum correct value for RGB is 255, because value 0 is also one value) and then on the same row you go back to Screen 0. Is this correct? Then next print is not created to page& but to screen 0.

You can also use _DEST in this way:

Current_Screen = _DEST
_Dest Virtual_Screen
print here something....
_Dest Current_Screen       for return back from virtual screen to previous visible screen

Please check, if this is correct in your program.
« Last Edit: July 29, 2019, 09:10:01 am by Petr »

Offline Petr

  • Forum Resident
  • Posts: 1720
  • The best code is the DNA of the hops.
    • View Profile
Re: Code to print out a barcode on a label printer works well
« Reply #3 on: July 29, 2019, 11:02:31 am »
I went through your code, the main problem why the label disappeared was that in the program you call SCREEN _NEWIMAGE which is page & at line 41 and after printing you call SCREEN 0, this of course switches the screen. To use virtual pages, you must assign a variable to the screen, such as Page & = _NEWIMAGE (800, 600, 32), this will create this virtual screen in memory. To make it visible, call SCREEN as follows: SCREEN Page &. Use _DEST to switch between screens.
I added your code, which I modified, please return the correct fonts yourself there. The _PUTIMAGE command I used to insert the Page & virtual screen on the current screen, you can do it smaller or larger, play with the coordinates and try. At the end of the program you have a primitive solution to ask whether to print or not. I don't know if your print will work as expected, try it and let me know.

Code: QB64: [Select]
  1. SCREEN _NEWIMAGE(800, 600, 32)
  2.  
  3.  
  4. PRINT "Barcode Printer code"
  5. PRINT "Tested and tweaked to use the "
  6. PRINT "Label designer for the Brother 201 (29mm x 90mm or 1-1/7 x 3-1/2)"
  7. PRINT "The Zebra, ZDesigner LP 2844 looks to be compatible too. no modifications made."
  8. PRINT "If you do not have it already You will need to search for free3of9x.ttf"
  9. PRINT "Redable text uses the windows Arial.ttf"
  10. PRINT "Should work with other Windows Font and the 128 code but not needed for my use"
  11. PRINT "Expire print out is formated for a date mm/dd/yyyy or a 10 character description"
  12. PRINT "What data do you want as the barcode data"
  13. INPUT "It is best not to exceed 9 characters ", DATAPASS1$
  14. DATAPASS1$ = "*" + DATAPASS1$ + "*"
  15. INPUT "Enter an Expireation date ", DATAPASS2$
  16. INPUT "Enter a Description Line 1 ", DATAPASS3$
  17. INPUT "Enter a Description Line 2 ", DATAPASS4$
  18. PRINT "--------------------------------------------------------------"
  19. PRINT "Serial " + DATAPASS1$ + "                         Use By "; DATAPASS2$
  20. PRINT DATAPASS3$
  21. PRINT DATAPASS4$
  22. PRINT "||| ||| || |||||||| |||||| |||||| ||||| | |||||| ||||||| |||||"
  23. PRINT "--------------------------------------------------------------"
  24. INPUT "As soon as you press enter the label will print", a
  25. 'FFONT$ = "free3of9x.ttf": FFSize = 120
  26. 'EFONT$ = "Arial.ttf": EFSize = 60
  27. 'AFONT$ = "Arial.ttf": AFSize = 60
  28. 'PageWidth = 216 * 10
  29. 'PageHeight = 279 * 10
  30.  
  31. 'Label designer for the Brother 201 (29mm x 90mm or 1-1/7" x 3-1/2") / Zebra ZDesigner LP 2844 looks compatible.
  32. FFONT$ = "Cyberbit.ttf": FFSize = 240 '                                                                                    i have not your TTF files, rewrite it back
  33. EFONT$ = "Cyberbit.ttf": EFSize = 40
  34. AFONT$ = "Cyberbit.ttf": AFSize = 40
  35. PageWidth = 110 * 10 'maximized tweaks for whole label
  36. PageHeight = 29 * 10 'Max is already set do not change.
  37.  
  38. Colum = 10
  39. a = 0
  40. page& = _NEWIMAGE(PageWidth, PageHeight, 256)
  41. current& = _DEST
  42. _DEST page&
  43. CLS _RGB(0, 0, 0), _RGB(255, 255, 255) 'make background white to save ink!
  44. F& = _LOADFONT(FFONT$, FFSize)
  45. E& = _LOADFONT(EFONT$, EFSize)
  46. A& = _LOADFONT(AFONT$, AFSize)
  47.  
  48. _FONT F&, page&
  49. _PRINTSTRING (Colum, 45), DATAPASS1$, page& ' Print upc bars on bottom of label
  50.  
  51. _FONT E&, page&
  52. _PRINTSTRING (400, 0), Title$, page& ' Print Line 1 description
  53.  
  54. _FONT A&, page&
  55. _PRINTSTRING (Colum, 35), DATAPASS3$, page& ' Print Line 2 ProductInventory description
  56. _PRINTSTRING (Colum, 68), DATAPASS4$, page& ' Print Line 3 ProductInventory description
  57.  
  58. _FONT A&, page&
  59. keep = LEN(DATAPASS1$): DATAPASS1$ = MID$(DATAPASS1$, 2, keep - 2)
  60. COLOR _RGB(1, 1, 1), _RGB(255, 255, 255): _PRINTSTRING (Colum, 0), "Serial " + DATAPASS1$ ' Print upc bar information above bar scan font
  61. IF DATAPASS2$ <> "" THEN COLOR _RGB(0, 0, 0), _RGB(255, 255, 255): _PRINTSTRING (725, 0), "Use By " + DATAPASS2$ ' Print Product Expiry Date
  62.  
  63.  
  64. 'show preview
  65.  
  66. _DEST current&
  67. _PUTIMAGE (100, 100)-(500, 250), page&, current&
  68.  
  69.  
  70. 'ask if print
  71. _PRINTSTRING (350, 500), "Print label? (Y/N)"
  72. DO UNTIL answer$ = "Y" OR answer$ = "N"
  73.     answer$ = UCASE$(INKEY$)
  74.  
  75. IF answer$ = "Y" THEN _PRINTIMAGE page& 'print screen page on printer
  76. 'if answer$ = "N" then.... query if create new label or exit in the same way as previous query...
  77.  
  78.  

Offline Chris80194

  • Newbie
  • Posts: 42
    • View Profile
Re: Code to print out a barcode on a label printer works well
« Reply #4 on: July 30, 2019, 01:58:39 am »
Petr I wacked this together for a complete printing program for labels with a 3 of 9 barcode the 128 does not seem to work and since it is not really needed I did not want to waste more labels adjusting the font size so it would also scan.

I cut this out to make it available to others that might want to print labels.
I have it set for my mom to print return labels and labels to the girls on the WPGA that she heads up.

Ill have a look at your code.  Thanks for edits, it is probably cleaner then mine.  I added and removed things until it did what I needed in my full code program.

Bplus yeah I was stopping the run to show what the label would look like before it prints out on the printer.
A pause in the actual label was causing a ? to appear in the screen that would then print on the actual label.
I put this on here so that others could use it, adjust it, clean it up some, and in general a decent place to start from.

My code is more like a monkey in a cage throwing feces.  throw things around and see what sticks.
« Last Edit: July 30, 2019, 02:20:13 am by Chris80194 »

Offline Chris80194

  • Newbie
  • Posts: 42
    • View Profile
Re: Code to print out a barcode on a label printer works well
« Reply #5 on: July 30, 2019, 02:27:08 am »
Petr
Nice output.
It was what I was going for.
I have a whole program that I have wacked keys on it does a decent job of input so now I have to work on retrieval.
the employee edit part sucks but that is a low priority to the other aspects that I am working towards.
Got rid of the append to file for random access hopefully much faster.
Sure there is code to remove edit and tweak.  Have a peek and a good laugh it's at.

https://www.qb64.org/forum/index.php?topic=1545.0

I am mashing things back and forth, then the next part will be retrieval and editing of the parts section...

Offline Chris80194

  • Newbie
  • Posts: 42
    • View Profile
Re: Code to print out a barcode on a label printer works well
« Reply #6 on: July 30, 2019, 02:53:11 am »
Petr
So I tried the printout and the barcode won't scan????  Most likely spacing.
I like the output this makes using any other font, some tweaking.
Would be good for making return labels and send to labels.

The Barcode has to be JUSssttttttttt--------rrrriiiiigghhHHTTTTT.
30 some wasted labels until I got one to read on the scanner.

Bplus that is what happened on the above code I supplied to start out with.
Trial by error until the label worked right.  Messy but functional, pretty much how I do most things.
LOL
Thanks,

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Code to print out a barcode on a label printer works well
« Reply #7 on: July 30, 2019, 09:18:07 am »
Ha! When I try stuff with printers, by the time I get it right, I am out of ink or paper.

(except a calendar thing which just printed a screen image)

Offline Chris80194

  • Newbie
  • Posts: 42
    • View Profile
Re: Code to print out a barcode on a label printer works well
« Reply #8 on: July 31, 2019, 09:35:10 pm »
Yeah pretty much what I did.
I was able to get the laser sheets right but had to buy a label printer to format it right.

The laser printer was just not formating it right.

so 40 bucks later a week wait and a trip to office depot for an extra 400 labels....

Got it all working  Then someone gave me a Zebra label printer,  it works too.

But yeah had to print adjust and print again.  That is where the mash came from.

I like how Petr's output looks but it is not working with my printers. (frown face)

really in my program, once the data is scanned in the last thing it does is make a serialized label for that box to be used for control purposes of a "perishable" product.
Also to check in and out that product you "scan" that serial number.