Link | jina_checksumUPC |
Author | Jolle Carlestam |
Category | Custom Tag |
Version | 8.5.x |
License | Public Domain |
Posted | 11 Mar 2009 |
Updated | 13 Mar 2009 |
More by this author... |
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.
jina_checksumUPC('036000241453'); -> true jina_checksumUPC('036000241456'); -> false jina_checksumUPC('03600024145', -add); -> 3
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;
No comments
©LassoSoft Inc 2015 | Web Development by Treefrog Inc | Privacy | Legal terms and Shipping | Contact LassoSoft