cfCode128 ( )

Function stats

Average user rating
131
182
9999
Support
FileMaker 10.0 +
Date posted
13 January 2009
Last updated
14 January 2009
Version
Recursive function
Yes

Author Info
 Tammo Fornalik / Felix Hausberner

1 functions

Average Rating None

author_avatar



 

Function overview

Prototype

cfCode128  ( pString;   pCodeSet )


Parameters

pString  string to be converted for use with barcode font


pCodeSet  Code128 variant.


Description

Tags:  Format   Barcode  

composes the final barcode Code128 of symbology A,B or C from a given alphanumeric string.
includes the checksum of the string (modulo 103) as well as start/stop characters.
this CF is meant to be used with barcode font "IDAutomationC128..."
http://www.advancemeants.com/code128fonts/download.htm

automatic switching between variants A,B,C within a single barcode is not yet supported.

pString: string to be used as a barcode.
pCodeSet: "A" or "B" or "C" are expected.
local var $i stores the actual count of loops.
be careful, $i var should not be used in a script running at the same time.
all vars (although locally stored) should be destroyed when the process is done.

author: tammo fornalik / felix hausberner, dbyte solutions, 01.06.2008
changes: 10.01.2009, Code() and Char() are now native functions in FM10, replaced references to CFs which did that job.

Examples

Sample input

cfCode128( "SBM16672_2008_08_25"; "B" )


Sample output

"SBM16672_2008_08_25" as Code128B including checksum and start/stop tags (viewable with IDAutomation Code128 fonts)

 

Function code

/*
cfCode128 ( pString; pCodeSet )

---use with FM version >= 10---
composes the final barcode Code128 of symbology A,B or C from a given alphanumeric string.
includes the checksum of the string (modulo 103) as well as start/stop characters.
this CF is meant to be used with barcode font "IDAutomationC128..."
http://www.advancemeants.com/code128fonts/download.htm

automatic switching between variants A,B,C within a single barcode is not yet supported.

pString: string to be used as a barcode.
pCodeSet: "A" or "B" or "C" are expected.
local var $i stores the actual count of loops.
be careful, $i var should not be used in a script running at the same time.
all vars (although locally stored) should be destroyed when the process is done.

author: tammo fornalik / felix hausberner, dbyte solutions, 01.06.2008
changes: 10.01.2009, Code() and Char() are now native functions in FM10, replaced references to CFs which did that job.
type: recursive
dependencies: none
call like: cfCode128( "SBM16672_2008_08_25"; "B" )
*/

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> String is empty -> no output
Case( IsEmpty( pString ); ""

//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> CodeSet A, B
; pCodeSet = "A" or pCodeSet = "B";

Let(
[
vInitOnce = Case( IsEmpty( $i );
//the following inits are only processed during initial call
Let(
[
$C128_Start = Char( Case( pCodeSet = "A"; 203; pCodeSet = "B"; 204; 0 ) ); //defined by C128 specs
$C128_Stop = Char( 206 ); //defined by C128 specs
$DataToEncode = Trim( pString );
$WeightedTotal = Code( $C128_Start ) -100; //font specific
$C128_CheckDigit = "w"; //font specific, on internal error
$i = 0
]; "" ); //end let
"" ); //end case

$i = $i +1;
//get the value of each character. calculate the WeightedTotal for modulo 103 checksum.
vCurrentChar = Code( Middle( $DataToEncode; $i; 1 ) );
vCurrentVal = Case( vCurrentChar < 135; vCurrentChar -32; vCurrentChar > 134; vCurrentChar -100 );
vCurrentVal = vCurrentVal * $i;
$WeightedTotal = $WeightedTotal + vCurrentVal
];

Case(
$i < Length( $DataToEncode ); cfCode128( $DataToEncode; pCodeSet ); //recursion
Let(
[
//divide the WeightedTotal by 103 and get the remainder, this is the CheckDigitValue
vChkDigitVal = Mod( $WeightedTotal; 103 );
//map CheckDigit to font specific chars
$C128_CheckDigit = Char( Case( vChkDigitVal = 0; 194; vChkDigitVal < 95 and vChkDigitVal > 0; vChkDigitVal +32; vChkDigitVal > 94; vChkDigitVal +100 ) );
$DataToEncode = Substitute ( $DataToEncode; Char( 32 ); Char( 194 ) ); //replace the spaces with the 194 character, font specific
vPrintableString = $C128_Start & $DataToEncode & $C128_CheckDigit & $C128_Stop;
$C128_Start=""; $C128_Stop=""; $DataToEncode=""; $C128_CheckDigit=""; $WeightedTotal=""; $i="" //kill vars
]; vPrintableString ) //end let
) //end case

) //end let


//>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> CodeSet C
; pCodeSet = "C";

Let(
[
vInitOnce = Case( IsEmpty( $i );
Let(
[
$C128_Start = Char( 205 );
$C128_Stop = Char( 206 );
$DataToEncode = Filter( pString ; "0123456789" );
vCountOfDigitsIsOdd = Mod( Length( $DataToEncode ); 2 ) = 1;
$DataToEncode = Case( vCountOfDigitsIsOdd; "0"; "" ) & $DataToEncode;
$DataToPrint = "";
$WeightValue = 0;
$WeightedTotal = Code( $C128_Start ) -100;
$C128_CheckDigit = "w";
$i = -1 //...so the first used value will be 1
]; "" ); //end let
"" ); //end case

$i = $i +2;
$WeightValue = $WeightValue +1;
vCurrentChar = Middle( $DataToEncode; $i; 2 );
$DataToPrint = $DataToPrint & Case( vCurrentChar < 95 and vCurrentChar > 0; Char( vCurrentChar +32 ); vCurrentChar > 94; Char( vCurrentChar +100 ); vCurrentChar = 0; Char( 194 ) );
$WeightedTotal = $WeightedTotal + (vCurrentChar * $WeightValue)
];

Case(
$i < Length( $DataToEncode ); cfCode128( $DataToEncode; pCodeSet ); //recursion
Let(
[
vChkDigitVal = Mod( $WeightedTotal; 103 );
$C128_CheckDigit = Char( Case( vChkDigitVal < 95 and vChkDigitVal > 0; vChkDigitVal +32; vChkDigitVal > 94; vChkDigitVal +100; vChkDigitVal = 0; 194 ) );
vPrintableString = $C128_Start & $DataToPrint & $C128_CheckDigit & $C128_Stop;
$C128_Start=""; $C128_Stop=""; $DataToEncode=""; $DataToPrint=""; $WeightValue=""; $C128_CheckDigit=""; $WeightedTotal=""; $i=""
]; vPrintableString ) //end let
) //end case

) //end let

) //end case

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

    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/182

    Prototype: cfCode128( pString; pCodeSet )
    Function Author: Tammo Fornalik / Felix Hausberner (http://www.fmfunctions.com/mid/131)
    Last updated: 14 January 2009
    Version: 1.2

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

 

 

 

 

 

 

 

Top Tags

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