Lasso Soft Inc. > Home

[jina_checksumUPC]

Linkjina_checksumUPC
AuthorJolle Carlestam
CategoryCustom Tag
Version8.5.x
LicensePublic Domain
Posted11 Mar 2009
Updated13 Mar 2009
More by this author...

Description

Tag to handle checksum calculation on a UPC number (Universal Product Code). It can either validate that a number ends with a correct checksum or add a checksum to a number.

Sample Usage

jina_checksumUPC('036000241453');
-> true

jina_checksumUPC('036000241456');
-> false

jina_checksumUPC('03600024145', -add);
-> 3

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_tag('checksumUPC', -namespace = 'jina_',
	-req = 'check', -copy,
	-opt = 'add'
);

// tag used for checksum calculation for the UPC barcode system
// usage jina_checksumUPC('NNNNNNNN')
// will return true or false depending on if the checksum checks
// usage with optional param -add jina_checksumUPC('NNNNNNNN', -add)
// returns the correct checksum for the checked value

	local('temp',
		'total' = integer,
		'odd' = integer,
		'checksum'
	);

	#check = string_replaceregexp(#check, -find = '[^0-9]', -replace = '');

	if(!local_defined('add'));
		#checksum = #check -> substring(#check -> size, 1);
		#check -> remove(#check -> size, 1);
	/if;

	iterate(#check, #temp); 
		if((loop_count % 2) == 1);
			#odd += integer(#temp);
		else;
			#total += integer(#temp);
		/if;
	/iterate;

	#total += (#odd * 3);

	if(local_defined('add'));
		return(#total % 10);
	else(#total % 10 == #checksum);
		return(true);
	else;
		return(false);
	/if;

/define_tag;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft