Jump to content
Sign in to follow this  
youknowwho4eva

Barcode Creator

Recommended Posts

youknowwho4eva

I know, I don't believe it either. I actually created something that someone other then myself might find useful. It's a barcode creator. I created this to help me with my next project. A barcode reader. For those of you that know about barcodes, it does not calculate the check digit for you but I plan to do that next.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <array.au3>
Global $bar[1000000]
Global $checkofcheck[10000000]
GUICreate("Barcode Maker",420,200)
GUISetBkColor(0xffffff)
$code = GUICtrlCreateInput("",110,140,140,20)
$check = GUICtrlCreateInput("",295,140,15,20)
GUICtrlSetState($check,@SW_DISABLE)
$go = GUICtrlCreateButton("Go", 155,165,50,25)
GUICtrlCreateLabel("Check Digit", 275,165)
GUICtrlCreateLabel("Auto Populates", 265,180)
For $b = 3 To 405 step +3
$bar[$b] = GUICtrlCreateGraphic(24 + $b,25,6,100)
GUICtrlSetBkColor(-1,0xffffff)
GUICtrlSetColor(-1,0xffffff)
Next
GUISetState(@SW_SHOW)
While 1
    $msg = GUIGetMsg()
    Select
    Case $msg = $gui_event_close
        Exit
    Case $msg = $go
        For $b = 3 To 405 step +3
        GUICtrlSetBkColor($bar[$b],0xffffff)
        GUICtrlSetColor($bar[$b],0xffffff)
    Next
    $tempcode = GUICtrlRead($code)
    $temparray = StringSplit($tempcode,"")
    For $t = 1 to $temparray[0] step +2
            If $t = 1 Then
                $oddsum = $temparray[$t]
            Else
                $oddsum = $temparray[$t] + $oddsum
            EndIf
        Next
        $multiplysum = $oddsum * 3
        For $t = 2 to $temparray[0] step +2
            If $t = 2 Then
                $evensum = $temparray[$t]
            Else
                $evensum = $temparray[$t] + $evensum
            EndIf
        Next
$sumofsums = $multiplysum + $evensum
For $m = 0 to 9
    $checkofcheck[$m] = ($sumofsums + $m) / 10
    If stringisint($checkofcheck[$m]) = 1 then
        $checkdigit = $m
        ExitLoop
    EndIf
    
Next
GUICtrlSetData($check,$checkdigit)

        $barcode = GUICtrlRead($code) & $checkdigit
        $array = StringSplit($barcode,"")
        
        guictrlsetbkcolor($bar[3],0)
        GUICtrlSetColor($bar[3],0)
        guictrlsetbkcolor($bar[9],0)
        GUICtrlSetColor($bar[9],0)
        For $n = 1 to ($array[0] / 2)
            If $n = 1 Then
            $one = 12
            
        Else
            $one = 12 + (21 * ($n-1))
        EndIf
        $two = $one + 3
        $three = $one + 6
        $four = $one + 9
        $five = $one + 12
        $six = $one + 15
        $seven = $one + 18
        If $array[$n] = "1" Then Call("one")
        If $array[$n] = "2" Then Call("two")
        If $array[$n] = "3" Then Call("three")
        If $array[$n] = "4" Then Call("four")
        If $array[$n] = "5" Then Call("five")
        If $array[$n] = "6" Then Call("six")
        If $array[$n] = "7" Then Call("seven")
        If $array[$n] = "8" Then Call("eight")
        If $array[$n] = "9" Then Call("nine")
        If $array[$n] = "0" Then Call("zero")
            
        Next
        $r = 12 + (21 * ($n-1))
        guictrlsetbkcolor($bar[$r + 3],0)
        GUICtrlSetColor($bar[$r + 3],0)
        guictrlsetbkcolor($bar[$r + 9],0)
        GUICtrlSetColor($bar[$r + 9],0)
        
        For $n = ($array[0] / 2) + 1 to $array[0]
            
                $one = 27 + (21 * ($n-1))
            
        $two = $one + 3
        $three = $one + 6
        $four = $one + 9
        $five = $one + 12
        $six = $one + 15
        $seven = $one + 18
        If $array[$n] = "1" Then Call("onei")
        If $array[$n] = "2" Then Call("twoi")
        If $array[$n] = "3" Then Call("threei")
        If $array[$n] = "4" Then Call("fouri")
        If $array[$n] = "5" Then Call("fivei")
        If $array[$n] = "6" Then Call("sixi")
        If $array[$n] = "7" Then Call("seveni")
        If $array[$n] = "8" Then Call("eighti")
        If $array[$n] = "9" Then Call("ninei")
        If $array[$n] = "0" Then Call("zeroi")
            
        Next
        $r = 27 + (21 * ($n-1))
        guictrlsetbkcolor($bar[$r],0)
        GUICtrlSetColor($bar[$r],0)
        guictrlsetbkcolor($bar[$r + 6],0)
        GUICtrlSetColor($bar[$r + 6],0)
        EndSelect
WEnd
Func one()
    guictrlsetbkcolor($bar[$three],0)
    GUICtrlSetColor($bar[$three],0)
    guictrlsetbkcolor($bar[$four],0)
    GUICtrlSetColor($bar[$four],0)
    guictrlsetbkcolor($bar[$seven],0)
    GUICtrlSetColor($bar[$seven],0)
EndFunc
    
Func two()
    guictrlsetbkcolor($bar[$three],0)
    GUICtrlSetColor($bar[$three],0)
    guictrlsetbkcolor($bar[$six],0)
    GUICtrlSetColor($bar[$six],0)
    guictrlsetbkcolor($bar[$seven],0)
    GUICtrlSetColor($bar[$seven],0)
EndFunc
Func three()
    guictrlsetbkcolor($bar[$two],0)
    GUICtrlSetColor($bar[$two],0)
    guictrlsetbkcolor($bar[$three],0)
    GUICtrlSetColor($bar[$three],0)
    guictrlsetbkcolor($bar[$four],0)
    GUICtrlSetColor($bar[$four],0)  
    guictrlsetbkcolor($bar[$five],0)
    GUICtrlSetColor($bar[$five],0)  
    guictrlsetbkcolor($bar[$seven],0)
    GUICtrlSetColor($bar[$seven],0) 
EndFunc 
Func four()
    guictrlsetbkcolor($bar[$two],0)
    GUICtrlSetColor($bar[$two],0)   
    guictrlsetbkcolor($bar[$six],0)
    GUICtrlSetColor($bar[$six],0)   
    guictrlsetbkcolor($bar[$seven],0)
    GUICtrlSetColor($bar[$seven],0) 
EndFunc 
Func five()
    guictrlsetbkcolor($bar[$two],0)
    GUICtrlSetColor($bar[$two],0)
    guictrlsetbkcolor($bar[$three],0)
    GUICtrlSetColor($bar[$three],0)
    guictrlsetbkcolor($bar[$seven],0)
    GUICtrlSetColor($bar[$seven],0) 
EndFunc 
Func six()
    guictrlsetbkcolor($bar[$two],0)
    GUICtrlSetColor($bar[$two],0)
    guictrlsetbkcolor($bar[$four],0)
    GUICtrlSetColor($bar[$four],0)  
    guictrlsetbkcolor($bar[$five],0)
    GUICtrlSetColor($bar[$five],0)
    guictrlsetbkcolor($bar[$six],0)
    GUICtrlSetColor($bar[$six],0)   
    guictrlsetbkcolor($bar[$seven],0)
    GUICtrlSetColor($bar[$seven],0) 
EndFunc 
Func seven()
    guictrlsetbkcolor($bar[$two],0)
    GUICtrlSetColor($bar[$two],0)   
    guictrlsetbkcolor($bar[$three],0)
    GUICtrlSetColor($bar[$three],0)
    guictrlsetbkcolor($bar[$four],0)
    GUICtrlSetColor($bar[$four],0)
    guictrlsetbkcolor($bar[$six],0)
    GUICtrlSetColor($bar[$six],0)   
    guictrlsetbkcolor($bar[$seven],0)
    GUICtrlSetColor($bar[$seven],0) 
EndFunc 
Func eight()
    guictrlsetbkcolor($bar[$two],0)
    GUICtrlSetColor($bar[$two],0)   
    guictrlsetbkcolor($bar[$three],0)
    GUICtrlSetColor($bar[$three],0)
    guictrlsetbkcolor($bar[$five],0)
    GUICtrlSetColor($bar[$five],0)
    guictrlsetbkcolor($bar[$six],0)
    GUICtrlSetColor($bar[$six],0)   
    guictrlsetbkcolor($bar[$seven],0)
    GUICtrlSetColor($bar[$seven],0) 
EndFunc 
Func nine()
    guictrlsetbkcolor($bar[$four],0)
    GUICtrlSetColor($bar[$four],0)
    guictrlsetbkcolor($bar[$six],0)
    GUICtrlSetColor($bar[$six],0)   
    guictrlsetbkcolor($bar[$seven],0)
    GUICtrlSetColor($bar[$seven],0) 
EndFunc 
Func zero()
    guictrlsetbkcolor($bar[$four],0)
    GUICtrlSetColor($bar[$four],0)
    guictrlsetbkcolor($bar[$five],0)
    GUICtrlSetColor($bar[$five],0)  
    guictrlsetbkcolor($bar[$seven],0)
    GUICtrlSetColor($bar[$seven],0) 
EndFunc 
Func onei()
    guictrlsetbkcolor($bar[$one],0)
    GUICtrlSetColor($bar[$one],0)
    guictrlsetbkcolor($bar[$two],0)
    GUICtrlSetColor($bar[$two],0)
    guictrlsetbkcolor($bar[$five],0)
    GUICtrlSetColor($bar[$five],0)
    guictrlsetbkcolor($bar[$six],0)
    GUICtrlSetColor($bar[$six],0)
EndFunc
    
Func twoi()
    guictrlsetbkcolor($bar[$one],0)
    GUICtrlSetColor($bar[$one],0)
    guictrlsetbkcolor($bar[$two],0)
    GUICtrlSetColor($bar[$two],0)
    guictrlsetbkcolor($bar[$four],0)
    GUICtrlSetColor($bar[$four],0)
    guictrlsetbkcolor($bar[$five],0)
    GUICtrlSetColor($bar[$five],0)
EndFunc
Func threei()
    guictrlsetbkcolor($bar[$one],0)
    GUICtrlSetColor($bar[$one],0)
    guictrlsetbkcolor($bar[$six],0)
    GUICtrlSetColor($bar[$six],0)
EndFunc 
Func fouri()
    guictrlsetbkcolor($bar[$one],0)
    GUICtrlSetColor($bar[$one],0)   
    guictrlsetbkcolor($bar[$three],0)
    GUICtrlSetColor($bar[$three],0) 
    guictrlsetbkcolor($bar[$four],0)
    GUICtrlSetColor($bar[$four],0)  
    guictrlsetbkcolor($bar[$five],0)
    GUICtrlSetColor($bar[$five],0)
EndFunc 
Func fivei()
    guictrlsetbkcolor($bar[$one],0)
    GUICtrlSetColor($bar[$one],0)
    guictrlsetbkcolor($bar[$four],0)
    GUICtrlSetColor($bar[$four],0)
    guictrlsetbkcolor($bar[$five],0)
    GUICtrlSetColor($bar[$five],0)
    guictrlsetbkcolor($bar[$six],0)
    GUICtrlSetColor($bar[$six],0)   
EndFunc 
Func sixi()
    guictrlsetbkcolor($bar[$one],0)
    GUICtrlSetColor($bar[$one],0)
    guictrlsetbkcolor($bar[$three],0)
    GUICtrlSetColor($bar[$three],0) 
EndFunc 
Func seveni()
    guictrlsetbkcolor($bar[$one],0)
    GUICtrlSetColor($bar[$one],0)
    guictrlsetbkcolor($bar[$five],0)
    GUICtrlSetColor($bar[$five],0)
EndFunc 
Func eighti()
    guictrlsetbkcolor($bar[$one],0)
    GUICtrlSetColor($bar[$one],0)   
    guictrlsetbkcolor($bar[$four],0)
    GUICtrlSetColor($bar[$four],0)
EndFunc 
Func ninei()
    guictrlsetbkcolor($bar[$one],0)
    GUICtrlSetColor($bar[$one],0)
    guictrlsetbkcolor($bar[$two],0)
    GUICtrlSetColor($bar[$two],0)   
    guictrlsetbkcolor($bar[$three],0)
    GUICtrlSetColor($bar[$three],0) 
    guictrlsetbkcolor($bar[$five],0)
    GUICtrlSetColor($bar[$five],0)
EndFunc 
Func zeroi()
    guictrlsetbkcolor($bar[$one],0)
    GUICtrlSetColor($bar[$one],0)
    guictrlsetbkcolor($bar[$two],0)
    GUICtrlSetColor($bar[$two],0)   
    guictrlsetbkcolor($bar[$three],0)
    GUICtrlSetColor($bar[$three],0)
    guictrlsetbkcolor($bar[$six],0)
    GUICtrlSetColor($bar[$six],0)   
EndFunc
Edited by youknowwho4eva

Giggity

Share this post


Link to post
Share on other sites
TehWhale

Really nice!

Share this post


Link to post
Share on other sites
youknowwho4eva

Thank you much. When I'm done the scanner you'll be able to check if my barcode is right :-P.


Giggity

Share this post


Link to post
Share on other sites
DexterMorgan

good job :mellow:


code

Share this post


Link to post
Share on other sites
gseller

Nice!! I don't have much use for barcodes but very nice scripting..

Share this post


Link to post
Share on other sites
ptrex
youknowwho4eva

I'm not sure exactly what you mean... But this is the site I used to make the code. http://electronics.howstuffworks.com/upc3.htm. Next I'm going to use the first page to auto calculate the check digit. All I know is this is the barcode we use here at work.

Edit: I just looked at yours, It appears the difference is that the one I looked up multiply the sum of the odds by 3

Edited by youknowwho4eva

Giggity

Share this post


Link to post
Share on other sites
ptrex

Share this post


Link to post
Share on other sites
youknowwho4eva

Thanks ptrex, I added it in the description.


Giggity

Share this post


Link to post
Share on other sites
TheSaint

I dream of one day being able to purchase a cheap hand-held scanner, that I can use for scanning the barcodes from Books, CD's, DVD's, etc. Where all the required detail is stored on a master database somewhere, for easy retrieval. :mellow:

OH WELL .... I'll keep on dreaming .... :(


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
youknowwho4eva

Added (unless your fast soon to add) new with check sum calculator. Yes I know its not as pretty as it was, but that check digit stuff is weirdest of all. @thesaint my plan is to have a scanner that you should be able to scan your code with a desktop scanner and read it as long as its a upc.

Also if someone wants to, I'd like to have a print button for this that would just print the bar code. But that's way on the back burner, so if someone has some free time and is willing too, please by all means add a print function


Giggity

Share this post


Link to post
Share on other sites
TheSaint

@thesaint my plan is to have a scanner that you should be able to scan your code with a desktop scanner and read it as long as its a upc.

Using a desktop scanner might seem alright at first glance (and at least that would be a start), but think about it.

Setting up your scanner for each item - both the time & fuss element would drive you crazy if you had any sizeable collections. It would probably be less fuss to put CD's & DVD's in your drive and query FreeDB, etc. And maybe less painful to type in all the ISBN numbers for books. Etc. AND I'VE FOUND THEM PAINFUL ENOUGH!

A little hand-held scanner with the right program and the all important on-line database, would make it heeps faster.

I think I'll go back to dreaming again .... zzzz


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites
youknowwho4eva

lol yes for that application, the reason I need a desktop one is we are emailed upc's and we need to verify them. Instead of printing and scanning it would be a lot easier for us to swipe our mouse.


Giggity

Share this post


Link to post
Share on other sites
serdem

Good job!, thank you for sharing. :mellow:

For better performance I recommend you to use only one GUICtrlCreateGraphic command and modify it by multiple GUICtrlSetGraphic commands for black and white bars.

Here is a sample code. It is not a real barcode, just look and feel.

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

    $GUI = GUICreate("My Draw")
    $areaWidth = 350
    $areaHeight = 50
    $margin = 8
    $height = 35
    $ypos = ($areaHeight - $height) / 2
    $area = GUICtrlCreateGraphic(20, 10, $areaWidth, $areaHeight)
    GUICtrlSetBkColor(-1, 0xFFFFFF)
    GUICtrlSetGraphic(-1, $GUI_GR_COLOR, 0x000000, 0x000000)

    $xpos = $margin
    While ($xpos + $margin ) < $areaWidth
        $black = Random(1,5,1)
        $white = Random(1,3,1)
        GUICtrlSetGraphic(-1, $GUI_GR_RECT, $xpos, $ypos, $black, $height)
        $xpos += $black + $white
    WEnd

    GUISetState()

    Do
        $msg = GUIGetMsg()
    Until $msg = $GUI_EVENT_CLOSE

Share this post


Link to post
Share on other sites
youknowwho4eva

Thanks, I'll have to take a look at then when I get the scanner to work a lot better.


Giggity

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  

×