GenerateEAN13_Raw ( )

Function stats

Average user rating
505
385
9999
Support
FileMaker 7.0 +
Date posted
12 August 2015
Last updated
13 August 2015
Version
Recursive function
No

Author Info
 Mc128k

1 functions

Average Rating None

author_avatar



 

Function overview

Prototype

GenerateEAN13_Raw  ( Input )


Parameters

Input  The input code (12 numbers)


Description

This is used to generate EAN13 barcodes with a single function, this generates a series of 0 and 1, which can be converted to an EAN code with a series of font blocks (█) or a bmp/png base64 generator. Input a number that is exactly 12 characters.

Entirely created by me, free to use, always credit my name and site in the code please.

Examples

Sample input

389127989919


Sample output

10101101110001011011001100110110010001000101101010100100011101001110100110011011101001110010101

 

Function code

// Copyright 2015 Mc128k
// www.mc128k.info
// Free to use, keep my name please

Let([
    $Code = Input;
    $Length = Length(Filter( $Code; "1234567890"))
];
    If ( $Length ≠ 12 ; "length not 12: " & $Length & $Input;
    Let([
        $Sum_Odd=Middle($Code; 2; 1) + Middle($Code; 4; 1) + Middle($Code; 6; 1) + Middle($Code; 8; 1) + Middle($Code; 10; 1) + Middle($Code; 12; 1);
        $Sum_Even=Middle($Code; 1; 1) + Middle($Code; 3; 1) + Middle($Code; 5; 1) + Middle($Code; 7; 1) + Middle($Code; 9; 1) + Middle($Code; 11; 1);
        $Checksum=Mod(10 - Mod(((3 * $Sum_Odd) + $Sum_Even) ; 10 ) ; 10);
        $Data=$Code & $Checksum;

        $EAN_Start="101";
        $EAN_Intermediate="01010";
        $EAN_Stop="101";

        $Eval=Middle($Data; 1; 1);
        $Mask=Case (     $Eval=0 ; "000000" ;
                    $Eval=1 ; "001011" ;
                    $Eval=2 ; "001101" ;
                    $Eval=3 ; "001110" ;
                    $Eval=4 ; "010011" ;
                    $Eval=5 ; "011001" ;
                    $Eval=6 ; "011100" ;
                    $Eval=7 ; "010101" ;
                    $Eval=8 ; "010110" ;
                    $Eval=9 ; "011010" );

        $P1_1=    Let([$n = 1 ; $d=Middle($Data;$n + 1;1)];
                    Case($d=0 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0001101" ; "0100111" ) ;
                        $d=1 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0011001" ; "0110011" ) ;
                        $d=2 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0010011" ; "0011011" ) ;
                        $d=3 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0111101" ; "0100001" ) ;
                        $d=4 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0100011" ; "0011101" ) ;
                        $d=5 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0110001" ; "0111001" ) ;
                        $d=6 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0101111" ; "0000101" ) ;
                        $d=7 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0111011" ; "0010001" ) ;
                        $d=8 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0110111" ; "0001001" ) ;
                        $d=9 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0001011" ; "0010111" )
                        ));
        $P1_2=    Let([$n = 2 ; $d=Middle($Data;$n + 1;1)];
                    Case($d=0 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0001101" ; "0100111" ) ;
                        $d=1 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0011001" ; "0110011" ) ;
                        $d=2 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0010011" ; "0011011" ) ;
                        $d=3 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0111101" ; "0100001" ) ;
                        $d=4 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0100011" ; "0011101" ) ;
                        $d=5 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0110001" ; "0111001" ) ;
                        $d=6 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0101111" ; "0000101" ) ;
                        $d=7 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0111011" ; "0010001" ) ;
                        $d=8 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0110111" ; "0001001" ) ;
                        $d=9 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0001011" ; "0010111" )
                        ));
        $P1_3=    Let([$n = 3 ; $d=Middle($Data;$n + 1;1)];
                    Case($d=0 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0001101" ; "0100111" ) ;
                        $d=1 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0011001" ; "0110011" ) ;
                        $d=2 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0010011" ; "0011011" ) ;
                        $d=3 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0111101" ; "0100001" ) ;
                        $d=4 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0100011" ; "0011101" ) ;
                        $d=5 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0110001" ; "0111001" ) ;
                        $d=6 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0101111" ; "0000101" ) ;
                        $d=7 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0111011" ; "0010001" ) ;
                        $d=8 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0110111" ; "0001001" ) ;
                        $d=9 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0001011" ; "0010111" )
                        ));
        $P1_4=    Let([$n = 4 ; $d=Middle($Data;$n + 1;1)];
                    Case($d=0 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0001101" ; "0100111" ) ;
                        $d=1 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0011001" ; "0110011" ) ;
                        $d=2 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0010011" ; "0011011" ) ;
                        $d=3 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0111101" ; "0100001" ) ;
                        $d=4 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0100011" ; "0011101" ) ;
                        $d=5 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0110001" ; "0111001" ) ;
                        $d=6 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0101111" ; "0000101" ) ;
                        $d=7 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0111011" ; "0010001" ) ;
                        $d=8 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0110111" ; "0001001" ) ;
                        $d=9 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0001011" ; "0010111" )
                        ));
        $P1_5=    Let([$n = 5 ; $d=Middle($Data;$n + 1;1)];
                    Case($d=0 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0001101" ; "0100111" ) ;
                        $d=1 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0011001" ; "0110011" ) ;
                        $d=2 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0010011" ; "0011011" ) ;
                        $d=3 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0111101" ; "0100001" ) ;
                        $d=4 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0100011" ; "0011101" ) ;
                        $d=5 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0110001" ; "0111001" ) ;
                        $d=6 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0101111" ; "0000101" ) ;
                        $d=7 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0111011" ; "0010001" ) ;
                        $d=8 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0110111" ; "0001001" ) ;
                        $d=9 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0001011" ; "0010111" )
                        ));
        $P1_6=    Let([$n = 6 ; $d=Middle($Data;$n + 1;1)];
                    Case($d=0 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0001101" ; "0100111" ) ;
                        $d=1 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0011001" ; "0110011" ) ;
                        $d=2 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0010011" ; "0011011" ) ;
                        $d=3 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0111101" ; "0100001" ) ;
                        $d=4 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0100011" ; "0011101" ) ;
                        $d=5 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0110001" ; "0111001" ) ;
                        $d=6 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0101111" ; "0000101" ) ;
                        $d=7 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0111011" ; "0010001" ) ;
                        $d=8 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0110111" ; "0001001" ) ;
                        $d=9 ; If ( Middle($Mask ; $n ; 1) = 0 ; "0001011" ; "0010111" )
                        ));

        $P2_1=    Let([$n = 1 ; $d=Middle($Data;$n + 1 + 6 ;1)];
                    Case($d=0 ; "1110010" ;
                        $d=1 ; "1100110" ;
                        $d=2 ; "1101100" ;
                        $d=3 ; "1000010" ;
                        $d=4 ; "1011100" ;
                        $d=5 ; "1001110" ;
                        $d=6 ; "1010000" ;
                        $d=7 ; "1000100" ;
                        $d=8 ; "1001000" ;
                        $d=9 ; "1110100"
                        ));
        $P2_2=    Let([$n = 2 ; $d=Middle($Data;$n + 1 + 6 ;1)];
                    Case($d=0 ; "1110010" ;
                        $d=1 ; "1100110" ;
                        $d=2 ; "1101100" ;
                        $d=3 ; "1000010" ;
                        $d=4 ; "1011100" ;
                        $d=5 ; "1001110" ;
                        $d=6 ; "1010000" ;
                        $d=7 ; "1000100" ;
                        $d=8 ; "1001000" ;
                        $d=9 ; "1110100"
                        ));
        $P2_3=    Let([$n = 3 ; $d=Middle($Data;$n + 1 + 6 ;1)];
                    Case($d=0 ; "1110010" ;
                        $d=1 ; "1100110" ;
                        $d=2 ; "1101100" ;
                        $d=3 ; "1000010" ;
                        $d=4 ; "1011100" ;
                        $d=5 ; "1001110" ;
                        $d=6 ; "1010000" ;
                        $d=7 ; "1000100" ;
                        $d=8 ; "1001000" ;
                        $d=9 ; "1110100"
                        ));
        $P2_4=    Let([$n = 4 ; $d=Middle($Data;$n + 1 + 6 ;1)];
                    Case($d=0 ; "1110010" ;
                        $d=1 ; "1100110" ;
                        $d=2 ; "1101100" ;
                        $d=3 ; "1000010" ;
                        $d=4 ; "1011100" ;
                        $d=5 ; "1001110" ;
                        $d=6 ; "1010000" ;
                        $d=7 ; "1000100" ;
                        $d=8 ; "1001000" ;
                        $d=9 ; "1110100"
                        ));
        $P2_5=    Let([$n = 5 ; $d=Middle($Data;$n + 1 + 6 ;1)];
                    Case($d=0 ; "1110010" ;
                        $d=1 ; "1100110" ;
                        $d=2 ; "1101100" ;
                        $d=3 ; "1000010" ;
                        $d=4 ; "1011100" ;
                        $d=5 ; "1001110" ;
                        $d=6 ; "1010000" ;
                        $d=7 ; "1000100" ;
                        $d=8 ; "1001000" ;
                        $d=9 ; "1110100"
                        ));
        $P2_6=    Let([$n = 6 ; $d=Middle($Data;$n + 1 + 6 ;1)];
                    Case($d=0 ; "1110010" ;
                        $d=1 ; "1100110" ;
                        $d=2 ; "1101100" ;
                        $d=3 ; "1000010" ;
                        $d=4 ; "1011100" ;
                        $d=5 ; "1001110" ;
                        $d=6 ; "1010000" ;
                        $d=7 ; "1000100" ;
                        $d=8 ; "1001000" ;
                        $d=9 ; "1110100"
                        ));
    
        $Part_1=$P1_1 & $P1_2 & $P1_3 & $P1_4 & $P1_5 & $P1_6;
        $Part_2=$P2_1 & $P2_2 & $P2_3 & $P2_4 & $P2_5 & $P2_6
    ];

    $EAN_Start & $Part_1 & $EAN_Intermediate & $Part_2 & $EAN_Stop

    ) // Let
    ) // If $Length
) // Let

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/385

    Prototype: GenerateEAN13_Raw( Input )
    Function Author: Mc128k (http://www.fmfunctions.com/mid/505)
    Last updated: 13 August 2015
    Version: 1.3

*/
// ===================================

 

 

 

 

 

 

 

Top Tags

Text Parsing  (33)
List  (32)
Date  (28)
XML  (26)
Format  (23)
Sql  (22)
Dev  (20)
Debug  (17)
Layout  (15)
Interface  (15)
Text  (14)
Filter  (12)
Variables  (12)
Layout Objects  (11)
Design  (10)
Array  (8)