Why Java not working

I’m trying to take in a text file and create a report with it almost verbatim, however I need to get some proper paging in it.

I’m trying do this with a script to read in all the lines. If there is a better way, please let me know. I also haven’t figured out the best way to force paging, so any input you have there is appreciated as well.

It’s working, sorta…because of the line in red below, it gives me this error on my extraction step:

Error running script (Wrapped java.lang.Exception: The step is out of bound (DME000130) (#10)) (DME000019)

If I comment that line out, it does work, just not quite how I want it to.

var theEnd = false;
var LineOffset = 0;
var CurrentLine =“”;
var numBlanks = 0;
var strData = “”;
var blanklines = 0;
strData = “<p>”;

while(!(theEnd))
{
CurrentLine = data.extract(1,85,LineOffset,1);

if ((CurrentLine.trim() === "") || (CurrentLine.trim() === undefined)){numBlanks ++;}
else {numBlanks = 0;}

if(CurrentLine.match(/5.00.30/g) == null)
{
    if (numBlanks &lt; 3 || CurrentLine.trim() != "")
        {strData += CurrentLine.replace(/ /gim, '&amp;nbsp;') + numBlanks + '&lt;br/&gt;';}
}
else
{
    strData += '&lt;/p&gt;&lt;p style="page-break-after: always;"&gt;&amp;nbsp&lt;/p&gt;&lt;p&gt;';
}

if (numBlanks &gt;= 15 )
{
    strData += "&lt;/p&gt;";
    theEnd = true;
}
LineOffset++;

}
result = strData;

I’m trying to read in each line, strip out any extra lines(more than 1 blank line at a time), and if I run into a 5.00.30 in the report to ignore that line and page there.

Difficult to help you without some sample data, but here’s some modified code that uses a try…catch construct to avoid getting out of bounds errors. Maybe that will help you move forward with your project:

var theEnd = false;
var LineOffset = 0;
var CurrentLine ="";
var numBlanks = 0;
var strData = "";
var blanklines = 0;
strData = "<p>";


while(!(theEnd))
{
 try {
     CurrentLine = data.extract(1,85,LineOffset,1);
 } catch(err) {
  logger.error("End of document reached: exiting after "+LineOffset+" loops");
  theEnd = true;
  break;
 }
   
    if ((CurrentLine.trim() === "") || (CurrentLine.trim() === undefined)) {
     numBlanks ++;
    } else {
     numBlanks = 0;
    }


    if(CurrentLine.match(/5.00.30/g) == null) {
        if (numBlanks < 3 || CurrentLine.trim() != "") {
         strData += CurrentLine.replace(/ /gim, '&nbsp;') + numBlanks + '<br/>';
        }
    } else {
        strData += '</p><p style="page-break-after: always;">&nbsp</p><p>';
    }
   
    if (numBlanks >= 15 ) {
        strData += "</p>";
        theEnd = true;
    }
    LineOffset++;
}
result = strData;

Thanks, Phil, that did the trick! It was throwing the error on the wrong line, and that sent me down the wrong path.