Sign in to follow this  
Followers 0
llewxam

UPC-A Generator for labels

5 posts in this topic

I recently made a label maker for Code39 and in doing I came up with a pretty novel way to save a LOT of time and effort in coding how the label was generated. I revisited my years-old UPC-A generator and using the same method cut it down from 150 lines of code to 41!!

I am skipping the whole checkbit validation thing as that has been covered in other posts before, and you will also need to change the label dimensions to match whatever Avery-style sheets you prefer and throw a _ScreenCapture_CaptureWnd in there and jump out of the Do loop. Finally using _WordDocAddPicture as shown by big_daddy you have the makings of a nice label maker! :D

Enjoy

Ian

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>

Local $UPCHor, $UPCHorInc = 2, $MagicColor = 1

$Code = "210168901587"

$BC = GUICreate("Label Image", 384, 155, 1, 1, $WS_EX_TOPMOST)
GUISetBkColor(0xffffff, $BC)
GUISetFont(Default, Default, Default, "Arial")
$BarcodeDigitsDisplay = GUICtrlCreateLabel(StringMid($Code, 1, 3) & " " & StringMid($Code, 4, 3) & " " & StringMid($Code, 7, 3) & " " & StringMid($Code, 10, 3), 5, 105, 380, 20, $SS_CENTER)
GUICtrlSetFont($BarcodeDigitsDisplay, 11, 400, 0, "Verdana")
$BCBox = GUICtrlCreateGraphic(76, 75, 100, 33)
GUICtrlSetGraphic($BCBox, $GUI_GR_PENSIZE, 2)
GUICtrlSetGraphic($BCBox, $GUI_GR_COLOR, 0)
_UPC($Code)
GUISetState(@SW_SHOW, $BC)

Do
$MSG = GUIGetMsg()
If $MSG == $GUI_EVENT_CLOSE Then ExitLoop
Until True == False
Exit

Func _UPC($ThisCode)
$MagicColor = 1
$UPCHor = 22
$UPCBreak = StringSplit($ThisCode, "")
_Blocker()
For $a = 1 To 12
If $a == 7 Then
$MagicColor = 0
$UPCHor += $UPCHorInc
_Blocker()
EndIf
If $UPCBreak[$a] == "0" Then _DrawUPC("0001101")
If $UPCBreak[$a] == "1" Then _DrawUPC("0011001")
If $UPCBreak[$a] == "2" Then _DrawUPC("0010011")
If $UPCBreak[$a] == "3" Then _DrawUPC("0111101")
If $UPCBreak[$a] == "4" Then _DrawUPC("0100011")
If $UPCBreak[$a] == "5" Then _DrawUPC("0110001")
If $UPCBreak[$a] == "6" Then _DrawUPC("0101111")
If $UPCBreak[$a] == "7" Then _DrawUPC("0111011")
If $UPCBreak[$a] == "8" Then _DrawUPC("0110111")
If $UPCBreak[$a] == "9" Then _DrawUPC("0001011")
Next
_Blocker()
EndFunc ;==>_UPC
Func _DrawUPC($Pattern)
$UPCPatternBreak = StringSplit($Pattern, "")
For $a = 1 To 7
If $UPCPatternBreak[$a] == $MagicColor Then
GUICtrlSetGraphic($BCBox, $GUI_GR_MOVE, $UPCHor, 2)
GUICtrlSetGraphic($BCBox, $GUI_GR_LINE, $UPCHor, 20)
EndIf
$UPCHor += $UPCHorInc
Next
EndFunc ;==>_DrawUPC
Func _Blocker()
GUICtrlSetGraphic($BCBox, $GUI_GR_MOVE, $UPCHor, 2)
GUICtrlSetGraphic($BCBox, $GUI_GR_LINE, $UPCHor, 29)
$UPCHor += $UPCHorInc * 2
GUICtrlSetGraphic($BCBox, $GUI_GR_MOVE, $UPCHor, 2)
GUICtrlSetGraphic($BCBox, $GUI_GR_LINE, $UPCHor, 29)
$UPCHor += $UPCHorInc * 2
EndFunc ;==>_Blocker

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.

Share this post


Link to post
Share on other sites



hehe, there's one in every crowd :D

I'll be more specific - funcs _UPC, _DrawUPC, and _Blocker are 41 lines. The rest of the code (and the includes) are building the GUI to demonstrate how the functions work. :huh:

Ian


My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

I didn't code this version to be as compact as the original post, honestly I just did this really quickly as I had a need to generate UPCs via command prompt and have it work without using ScreenCapture.  Since it was a pretty fun thing to code I thought I'd share it, hopefully some others will find it useful or interesting.

Enjoy

Ian

Edit - DOH!  I forgot to mention what makes this different!  It is using _GDIPlus_BitmapSetPixel to inject the lines in to a bitmap file.

upc_bmp.au3

Edited by llewxam

My projects:

  • IP Scanner - Multi-threaded ping tool to scan your available networks for used and available IP addresses, shows ping times, resolves IPs in to host names, and allows individual IPs to be pinged.
  • INFSniff - Great technicians tool - a tool which scans DriverPacks archives for INF files and parses out the HWIDs to a database file, and rapidly scans the local machine's HWIDs, searches the database for matches, and installs them.
  • PPK3 (Persistent Process Killer V3) - Another for the techs - suppress running processes that you need to keep away, helpful when fighting spyware/viruses.
  • Sync Tool - Folder sync tool with lots of real time information and several checking methods.
  • USMT Front End - Front End for Microsoft's User State Migration Tool, including all files needed for USMT 3.01 and 4.01, 32 bit and 64 bit versions.
  • Audit Tool - Computer audit tool to gather vital hardware, Windows, and Office information for IT managers and field techs. Capabilities include creating a customized site agent.
  • CSV Viewer - Displays CSV files with automatic column sizing and font selection. Lines can also be copied to the clipboard for data extraction.
  • MyDirStat - Lists number and size of files on a drive or specified path, allows for deletion within the app.
  • 2048 Game - My version of 2048, fun tile game.
  • Juice Lab - Ecigarette liquid making calculator.
  • Data Protector - Secure notes to save sensitive information.
  • VHD Footer - Add a footer to a forensic hard drive image to allow it to be mounted or used as a virtual machine hard drive.
  • Find in File - Searches files containing a specified phrase.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0