CETerm: Script to pad or strip scanned data to fixed length

Version 1

    Verified Product Versions

    Wavelink Naurtech CETerm 5.7

    This script manipulates the scanned barcode data to create a barcode of 11 characters.

    • If less than 11 characters, pads zeros before
    • If greater than 11 characters, strip remaining data after 11 characters
    • If 11 character, leave as is

     

    /*OnBarcodeRead*/ function OnBarcodeRead( session, data, source, type, date, time ) { var len = data.length;  // ----------------------------------------------------- 
    // If the scanned data is less than 11 characters, the 
    // pad it with zeros up to a length of 11 characters 
    // ----------------------------------------------------- 
    if (len < 11) 
    { 
    // pad data with zeros upto length of 11 characters 
    for (i=0; i < (11 - len); i++)
     { data = "0" + data; 
    } 
    }
    // ----------------------------------------------------- 
    // If the scanned data length is greater than 11 characters, 
    // strip any characters beyond the first 11 characters 
    // ----------------------------------------------------- 
    else if (len > 11) 
    { 
    data = data.substr(0, 11) }
    else 
    { 
    // If scanned data length is 11 characters, do nothing. 
    // Pass data to application
    // Send barcode to emulator 
    CETerm.SendText( data, session );  
    // Return 0 to handle barcode normally 
    // Return 1 if handled here 
    return 1;