Note: This was originally posted by an inactive account. Content was preserved by moving under an admin account.
Originally posted by: jchartrand*Edit* Javascript, not VB.
I have a big ask of the staff at lavastorm, and am hoping that someone can help me out here.
I am working on translating a very large javascript into brainscript. I've managed to make it through ~80% of the original javascript, but am held up on this last 20% that I have been trying to crack for a few days now.
Any help is greatly appreciated!
My reference field in the dataset is:
ScanCode
05615000009
06900000809
06210000010
06210000010
06210000009
06700000713
06210000240
06210000000
Javascript
function CalcCheckDigit(strMsg){
var Check = 0; # initialize the check digit value
for(var X = 1; X <= 11; X++){
var Test = strMsg.substr(X-1, 1);
if (isOdd(X)==true){
Check = Check + parseInt(Test) * 7; # odd position digits multiplied by 7
}
else{
Check = Check + parseInt(Test) * 9; # even position digits multiplied by 9
}
}
Check = (Check % 10) + 48; # convert value to ASCII character value;
return charFromCharCode (Check); # check character
}
function charFromCharCode (charCode) {
return unescape('%' + charCode.toString(16));
}
function isEven(y) {
return (y%2)?false:true;
}
function isOdd(y) {
return !isEven(y);
}
function mod(divisee,base) {
return Math.round(divisee - (Math.floor(divisee/base)*base));
}
function ConvertUPCAtoUPCE(UPCA,UPCE)
{
var csumTotal = 0; # The checksum working variable starts at zero
# If the source message string is less than 12 characters long, we make it 12 characters
if( UPCA.value.length < 12 )
{
var holdString = '000000000000' + UPCA.value;
UPCA.value = holdString.substring(holdString.length - 12, holdString.length);
}
if( UPCA.value.substring(0,1) != '0' && UPCA.value.substring(0,1) != '1')
UPCE.value = 'Invalid Number System (only 0 & 1 are valid)';
else
{
if( UPCA.value.substring(3,6) == '000' || UPCA.value.substring(3,6) == '100' ||
UPCA.value.substring(3,6) == '200' )
UPCE.value = UPCA.value.substring(1,3) + UPCA.value.substring(8,11) +
UPCA.value.substring(3,4);
else if( UPCA.value.substring(4,6) == '00' )
UPCE.value = UPCA.value.substring(1,4) + UPCA.value.substring(9,11) + '3';
else if( UPCA.value.substring(5,6) == '0' )
UPCE.value = UPCA.value.substring(1,5) + UPCA.value.substring(10,11) + '4';
else if( UPCA.value.substring(10,11) >= '5' )
UPCE.value = UPCA.value.substring(1,6) + UPCA.value.substring(10,11);
else
#Invalid product code (00005 to 00009 are valid)
alert('Invalid UPC-E Message');
}
document.forms["UPC"].txtUPCE.value = UPCE.value;
document.forms["UPC"].txtUPCE.focus();
}