Related sites:
More related sites:

Naurtech Support Wiki

Navigation: Print | Search | Wiki Home | Back to www.naurtech.com

Support Topics

  • Home
  • Usage Videos
  • Scripting
  • Web Browser
  • Download & Setup
  • License Registration
  • Cold Boot Persistence
  • Barcode Scanner
  • Remapping keys
  • Sounds & Tones
  • Lockdown & Fullscreen
  • Misc. & Usage Tips
  • Tools & Utilities

Wiki Actions

  • View
  • Edit
  • Print
Naurtech Corporation Copyright. All rights reserved.

Script to pad or strip scanned data to fixed length

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 charactes
  • If 11 character, leave as is

To download this sample, Right mouse click and select "Save Target As..." PadOrStripScanData.js
To load and run the script, see this article.

/*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;
}

The article is provided as a service to current and perspective Naurtech customers. Trademark references made to various companies and their products belong to the respective companies. All information is provided as is. For questions, please contact us at  support@naurtech.com.