Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Array.Push() Only Adding First Few Rows

New Here ,
Jul 07, 2016 Jul 07, 2016

Afternoon,

I am troubleshooting/supporting an in-house script for InDesign. What the script is designed to do is: We feed in a quote-delimited text file generated by an internal process. The script iterates through that, splits the lines as needed, adds them to an array, and populates a pre-existing template based on the contents.

However, for some reason, the Array.Push function that actually adds the split lines into the overall array isn't working properly. It adds up to twenty records, and then the rest just... disappear. Nothing's deleted, nothing's overwritten - but the first twenty records of a ~1000 record long file are the only ones that get picked up, and I'm not sure why. (To clarify: The loop goes through the whole file, and the Array.Push is successfully called on each iteration. It just doesn't seem to do anything, and the try/catch never fires.)

Any help would be very useful. There's more code than I've provided, and I can share it if need be, but this is the salient function.

function readDelimitedFile ( fPath, delimiter ) {

  var returnArray = new Array();

  var dataNames = new Array();

  var fileObject = File ( fPath ) ;

  if ( ! fileObject.exists ) {

    return returnArray ;

  }

  var escapedDelimiter = slashEscape(delimiter);

  var tabExpression = new RegExp ( escapedDelimiter ) ;

  try {

    fileObject.open ('r') ; //-- Open for reading.

   

    while ( ! fileObject.eof ) {

      var currentLine = fileObject.readln () ;

      if ( tabExpression.test( currentLine ) ) {

        var lineData = currentLine.split (delimiter);

        returnArray.push(lineData) ;       

      }

    }

    fileObject.close() ;

  }

  catch (errMain) {

    try {

      fileObject.close() ;

    }

    catch (errInner ) { }

  }

  return (returnArray);

}

TOPICS
Scripting
294
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Jul 07, 2016 Jul 07, 2016

Hi,

if you want some help here, you should provide excecutable code and a example of your e.g. 30-40 records.

Thanks

Kai

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Jul 08, 2016 Jul 08, 2016
LATEST

My guess is that it's a file encoding issue, try changing to utf8 or Unicode.

Probably the record that it stops at contains some problematic characters in it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines