Jump to content

barcode ean13


Gollem
 Share

Recommended Posts

For professional use I have develop a function witch generate barcode in ean13 standard with ean13.ttf font in pure autoit.

To use it:

You need to download the ean13.ttf from web. ( place it in windows\fonts)

It work anywhere: Excel, Word, Filemaker,notepad, ...

Feel free to include it in your scripts. Or save it as an include.

param $chaine = first 12 digits of your ean.

A feed back is welcome.

gollem

Func _EAN13($chaine)
  ; Traduit par Gollem d'un forum Vbasic
  ;'Paramètres : une chaine de 12 chiffres
  ;'Retour : * une chaine qui, affichée avec la police EAN13.TTF, donne le code barre
  ;'         * une chaine vide si paramètre fourni incorrect
  Dim $i, $checksum, $first, $CodeBarre, $tableA
  $EAN13 = ""
  
  ;'Vérifier qu'il y a 12 caractères
  If StringLen($chaine) = 12 Then
    ;Et que ce sont bien des chiffres
    For $i = 1 To 12
      If Asc(STRINGMid($chaine, $i, 1)) < 48 Or Asc(stringMid($chaine, $i, 1)) > 57 Then
            $i = 0
            Exit
        EndIf
    Next
  
  If $i = 13 Then
      ;'Calcul de la clé de contrôle

    For $i = 2 To 12 Step 2
        $checksum = $checksum + stringMid($chaine, $i, 1)
    Next
    
    $checksum = $checksum * 3

    For $i = 1 To 11 Step 2
        $checksum = $checksum + stringMid($chaine, $i, 1)
    Next
    
        ;MsgBox(0,"checksum",$checksum)
      $chaine = $chaine & 10-(mod ($checksum,10))
      ;MsgBox(0,"chaine",$chaine)
      
      ;Le premier chiffre est pris tel quel, le deuxième vient de la table A
      $CodeBarre = stringLeft($chaine, 1) & Chr(65 +(stringMid($chaine, 2, 1)))
      $first = stringLeft($chaine, 1)
      
      For $i = 3 To 7
        $tableA = False
      
      Select 
        Case $i = 3
          
          
                if $first = 0  Then $tableA = True
                if $first = 1  Then $tableA = True
                if $first = 2  Then $tableA = True  
                if $first = 3  Then $tableA = True              
        Case $i = 4
          
                if $first = 0  Then $tableA = True
                if $first = 4  Then $tableA = True
                if $first = 7  Then $tableA = True  
                if $first = 8  Then $tableA = True  
        Case $i = 5
          
                if $first = 0  Then $tableA = True
                if $first = 1  Then $tableA = True
                if $first = 4  Then $tableA = True  
                if $first = 5  Then $tableA = True
                if $first = 9  Then $tableA = True
        Case $i = 6
          
                if $first = 0  Then $tableA = True
                if $first = 2  Then $tableA = True
                if $first = 5  Then $tableA = True  
                if $first = 6  Then $tableA = True
                if $first = 7  Then $tableA = True
        Case $i = 7
          
                if $first = 0  Then $tableA = True
                if $first = 3  Then $tableA = True
                if $first = 6  Then $tableA = True  
                if $first = 8  Then $tableA = True
                if $first = 9  Then $tableA = True
        EndSelect

        If $tableA Then
          $CodeBarre = $CodeBarre & Chr(65 + stringMid($chaine, $i, 1))
        Else
          $CodeBarre = $CodeBarre & Chr(75 + stringMid($chaine, $i, 1))
        EndIf
      
      Next
        
        $CodeBarre = $CodeBarre & "*"   ;'Ajout séparateur central
        For $i = 8 To 13
            $CodeBarre = $CodeBarre & Chr(97 + stringMid($chaine, $i, 1))
        Next
        $CodeBarre = $CodeBarre  & "+"   ;'Ajout de la marque de fin
        $EAN13 = $CodeBarre
    return $ean13
EndIf
  EndIf
EndFunc
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...